Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7573749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:15:39+00:00 2026-05-30T16:15:39+00:00

i am getting funny data records like & whenever i tried export data records

  • 0

i am getting funny data records like & whenever i tried export data records from database using the export click. However, sometimes it works perfectly fine. Can anyone tell me why is it so and how can i solve the problem?

Sample code:

protected void CsvImg_Click(object sender, ImageClickEventArgs e)
{
    try
    {
        DataTable dataTable = (DataTable)Session["dataTable"];
        Response.ClearContent();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "sqlresult.csv"));
        Response.ContentType = "application/text";
        exportView.AllowPaging = false;
        exportView.DataSource = dataTable;
        exportView.DataBind();
        System.Text.StringBuilder strbldr = new System.Text.StringBuilder();
        for (int i = 0; i < exportView.HeaderRow.Cells.Count; i++)
        {
            //separting header columns text with comma operator
            strbldr.Append(exportView.HeaderRow.Cells[i].Text + ',');
        }
        //appending new line for gridview header row
        strbldr.Append("\n");
        for (int j = 0; j < exportView.Rows.Count; j++)
        {
            for (int i = 0; i < exportView.HeaderRow.Cells.Count; i++)
            {
                //separating gridview columns with comma
                strbldr.Append(exportView.Rows[j].Cells[i].Text + ',');
            }
            //appending new line for gridview rows
            strbldr.Append("\n");
        }
        Response.Write(strbldr.ToString());
        Response.End();
    }
    catch (Exception)
    {
    }
}

Import code:

    using (CsvFileReader reader = new CsvFileReader(CourseDataFileUpload.PostedFile.InputStream))
{
#region create dt
DataTable List = new DataTable();
List.Columns.Add("CourseID");
List.Columns.Add("CourseName");
List.Columns.Add("CourseCoordinator");
#endregion

CsvRow row = new CsvRow();
bool dataformat = false;
string checkname = "CourseID,CourseName,CourseCoordinator";

while (reader.ReadRowSpecial(row))
     {
for (int i = 0; i < row.Count; i++)
{
string total = HttpUtility.HtmlEncode(row[i].ToString());
if (total == checkname)
{
dataformat = true;
}

if (dataformat == true)
{
string[] splitname = total.Split(',');
#region split string
string first = splitname[0].ToString();
string second = splitname[1].ToString();
string third = splitname[2].ToString();
#endregion
List.Rows.Add(first, second, third);
listOfCourseInformation = List;
}
}
if (dataformat == false)
{
break;
}
}
if (List.Rows.Count > 0)
{
List.Rows.RemoveAt(0);
}
}

csv class:

public bool ReadRowSpecial(CsvRow row)
        {
            row.LineText = ReadLine();
            if (String.IsNullOrEmpty(row.LineText))
                return false;

            int pos = 0;
            int rows = 0;

            while (pos < row.LineText.Length)
            {
                string value;

                // Special handling for quoted field
                if (row.LineText[pos] == '"')
                {
                    // Skip initial quote
                    //pos++;

                    // Parse quoted value
                    int start = pos;
                    while (pos < row.LineText.Length)
                    {
                        // Test for quote character
                        if (row.LineText[pos] == '"')
                        {
                            // Found one
                            pos++;

                            // If two quotes together, keep one
                            // Otherwise, indicates end of value
                            if (pos >= row.LineText.Length || row.LineText[pos] != '"')
                            {
                                pos--;
                                break;
                            }
                        }
                        pos++;
                    }
                    value = row.LineText.Substring(start, pos - start);
                    value = value.Replace("\"\"", "\"");
                }
                else
                {
                    //Parse unquoted value
                    int start = pos;
                    while (pos < row.LineText.Length && row.LineText[pos] != '"')
                        pos++;
                    value = row.LineText.Substring(start, pos - start);
                }

                // Add field to list
                if (rows < row.Count)
                    row[rows] = value;
                else
                    row.Add(value);
                rows++;

                // Eat up to and including next comma
                while (pos < row.LineText.Length && row.LineText[pos] != '"')
                    pos++;
                if (pos < row.LineText.Length)
                    pos++;
            }
            //// Delete any unused items
            //while (row.Count > rows)
            //    row.RemoveAt(rows);

            // Return true if any columns read
            return (row.Count > 0);
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:15:40+00:00Added an answer on May 30, 2026 at 4:15 pm

    Pass all the strings to the below function before appending inside the StringBuilder.Append

    HttpUtility.HtmlDecode ()
    

    ex:

    strbldr.Append(HttpUtility.HtmlDecode(exportView.Rows[j].Cells[i].Text + ','));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing through some data using javascript and getting results like that look like
I am trying to select data from a DB2 database managed by another person
Getting the subdomain from a URL sounds easy at first. http://www.domain.example Scan for the
Getting started with NHibernate How can I generate identity fields in nHibernate using Hilo
Getting started with TDD and I want to ground up a Repository-driven Model. However,
Getting a 'marshal data too short' error when trying to install the mysql gem
Getting this error with jquery & jquery.form. Site has been live for awhile..upgraded to
Getting Json from the Server and displaying it in the grid is relatively straight
We're getting some funny behavior in the Visual Studio debugger with the following. I'm
Getting the following error when trying to run SPSS from an external Python IDE.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.