protected override void WriteFile(HttpResponseBase response) { response.Clear(); response.ClearContent(); response.ContentEncoding = System.Text.Encoding.Unicode; StreamWriter writer = new StreamWriter(response.OutputStream, Encoding.Default); writer.WriteLine("Test Data"); writer.Flush(); }Since "response.ContentEncoding = System.Text.Encoding.Unicode;" is assigned to correct encoding browse should enforce writing data in unicode format but point to remember is streamwriter is initialised with encoding as "Encoding.Default". So browse ignores content encoding. Modify your code to have
StreamWriter writer = new StreamWriter(response.OutputStream, Encoding.Unicode);Now this will enforce unicode format of the file. Also to verify if the file format is correct, rename the file to .bin and open Visual Studio to see the file in hex format. Verify the Byte Order Mark (BOM) of the file. First four char's "FF FE" confirms the file to be in unicode format. Refer to this article UTF-8, UTF-16, UTF-32 & BOM for more details about BOM.
Never trust anything that can think for itself if you can't see where it keeps its brain. ~J.K. Rowling
Thanks. Helped me to resolve a problem when exporting non-english characters...
ReplyDeleteGreat Article
ReplyDeleteASP.NET MVC Training
Online MVC Training
Online MVC Training India
Dot Net Training in Chennai
.Net Online Training
.net training online
Dot Net Online Training
Great Article
ReplyDeleteASP.NET MVC Training
Online MVC Training
Online MVC Training India
Dot Net Training in Chennai
.Net Online Training
.net training online
Dot Net Online Training
Nice! you are sharing such helpful and easy to understandable blog. i have no words for say i just say thanks because it is helpful for me.
ReplyDeleteDot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery