1

Here is my code for initiating download

System.Web.HttpContext.Current.Response.ClearContent();
        System.Web.HttpContext.Current.Response.Charset = "utf-8";
        System.Web.HttpContext.Current.Response.HeaderEncoding = UnicodeEncoding.UTF8;
        System.Web.HttpContext.Current.Response.ContentEncoding = UnicodeEncoding.UTF8;
        //System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
        System.Web.HttpContext.Current.Response.AddHeader("Content-Type", "text/csv");
        System.Web.HttpContext.Current.Response.AddHeader("Cache-Control", "max-age=0");
        System.Web.HttpContext.Current.Response.AddHeader("Accept-Ranges", "none");
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment" + "; filename=Data.csv");
        System.Web.HttpContext.Current.Response.BinaryWrite(buffer);
        System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();
        System.Web.HttpContext.Current.Response.Flush();
        System.Web.HttpContext.Current.Response.Close();
        args.AbortPipeline();

the out csv file contains like this at the place of some arabic letters

Data 99999;Arabic: ?????????????? ?????????????? al-abj;jkj;biluruya@mswork.ru;

I dont know why the UTF-8 encoding is not working here or is my download code wrong . could some one pls explain me the issue here ?

Thanks

  • Try this `Response.AppendHeader("Content-Disposition", "attachment; filename=Data.csv")` – Shawn Yan Jun 16 '16 at 03:34
  • Append header and add header are both same, my problem here is the encoding... – Jeyanth Praveenkumar Jun 16 '16 at 03:47
  • May be problem is not in the writing, it can be in reading file. Try opening the CSV file using a text editor like Notepad++. Select in the Encoding menu UTF8. – Anton Jun 16 '16 at 04:31
  • Also can you update you code to understand how you get buffer? May be buffer can contain wrong encoding. – Anton Jun 16 '16 at 04:33
  • buffer = Encoding.UTF8.GetBytes(csvfile.ToString()); this is my buffer which i am encoding and this currently works in notepad and i can able to see the arabic text. But when i open the same file in excel the arabic text is showing like special characters ? pls help – Jeyanth Praveenkumar Jun 16 '16 at 08:19
  • You could google for importing csv into excel with special characters. You will find some information, a.o. http://stackoverflow.com/questions/6002256/is-it-possible-to-force-excel-recognize-utf-8-csv-files-automatically – Gatogordo Jun 16 '16 at 11:37
  • Resolved the issue by adding utf8 preamble – Jeyanth Praveenkumar Jun 16 '16 at 12:19

0 Answers0