Create Text File Without BOM

Posted by balexandre on Stack Overflow See other posts from Stack Overflow or by balexandre
Published on 2010-03-23T19:32:45Z Indexed on 2010/03/23 19:33 UTC
Read the original article Hit count: 942

Filed under:
|
|
|

Hi guys,

I tried this aproach without any success

the code I'm using:

// File name
String filename = String.Format("{0:ddMMyyHHmm}", dtFileCreated);
String filePath = Path.Combine(Server.MapPath("App_Data"), filename + ".txt");

// Process                
ProcessPBS pbs = new ProcessPBS();
pbs.CreatePBSInfoFile(pbslist, Convert.ToInt64(filename));

// Save file
Encoding utf8WithoutBom = new UTF8Encoding(true);
TextWriter tw = new StreamWriter(filePath, false, utf8WithoutBom);
foreach (string s in pbs.GeneratedFile.ToArray())
    tw.WriteLine(s);
tw.Close();

// Push Generated File into Client
Response.Clear();
Response.ContentType = "application/vnd.text";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + ".txt");
Response.TransmitFile(filePath);
Response.End();

the result:

alt text

It's writing the BOM no matter what, and special chars (like Æ Ø Å) are not correct :-/

I'm stuck!

I can't create a file using UTF-8 as Encoding and 8859-1 as CharSet :-(

Anyone can help me find the light in the tunnel?

All help is greatly appreciated, thank you!

© Stack Overflow or respective owner

Related posts about textfiles

Related posts about c#