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 6906655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:20:15+00:00 2026-05-27T08:20:15+00:00

How to decode HTML to CSV with user default encoding? Every Response.ContentEncoding I use

  • 0

How to decode HTML to CSV with user default encoding? Every Response.ContentEncoding I use exports gibberish.

SQL to Grid:

SqlConnection conn = new SqlConnection(connectionString);                
string select = "SELECT...";
SqlDataAdapter DataCommand = new SqlDataAdapter(select, conn);
DataSet ds = new DataSet();
DataCommand.Fill(ds);
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();

Grid to CSV:

Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=CSVfile.csv");
Response.ContentType = "text/csv";
// other encoding like utf-8 also exports encoded data
Response.ContentEncoding = Encoding.GetEncoding("Windows-1250"); 

StringBuilder sb = new StringBuilder();      
for (int i = 0; i < GridView1.Rows.Count; i++)
{
    for (int k = 0; k < GridView1.Rows[0].Cells.Count; k++)
    {
        sb.Append(GridView1.Rows[i].Cells[k].Text + ';');
    }
    sb.Append("\r\n");
}
Response.Output.Write(sb.ToString());
Response.Flush()
Response.End();

SQL_Latin1_General_CP1_CI_AS data is displayed correctly as “Windows CP-1250” in Grid, however the CSV contains all the HTML encoded characters (&#243; instead of ó etc., same as in HTML source of grid). I’m totally lost with this encoding right now…

  • 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-27T08:20:16+00:00Added an answer on May 27, 2026 at 8:20 am

    The special characters you are seeing are not content encoded, they are HTML encoded. You need to HTML decode the string first.

    Try changing:

    Response.Output.Write(sb.ToString()); 
    

    to

    Response.Output.Write(HttpUtility.HtmlDecode(sb.ToString()));
    

    Be aware that you might want to do this line-by-line for very large strings

    (i.e. HTML decode the CSV out line by line):

    sb.Append(HttpUtility.HtmlDecode(GridView1.Rows[i].Cells[k].Text) + ';');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I use jQuery to decode HTML entities in a string?
I am trying to use Regular Expressions to decode some HTML I retrieve from
Is their a method to encode/decode HTML and URL (in Xcode, using Objective-C)? [NSString
I sent a text via GET method to decode html entities ( &#119; =
Basically, I would like to decode a given HTML document, and replace all special
Trying to decode an invalid encoded utf-8 html page gives different results in python,
I need to decode HTML entities, e.g. from &#246; to ö, and &amp; to
i was wondering if the crawlers and robots can decode html entities for example
I have a HTML string in ISO-8859-1 encoding. I need to pass this string
Possible Duplicate: Decode HTML entities in Python string? I have a malformed string in

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.