Write text file in ASP.Net - C# without Byte Order Mark
Posted on 2010-01-11
I'm using a StreamWriter in ASP.Net / C# to save a text file. However; I need to be able to write a file without having the Byte Order Mark (BOM) written at the beginning of the file. This requirement is needed because of a legacy program that reads in the text file and misinterprets the BOM.
The following code appends the three characters EF BB BF at the beginning of the file.
StreamWriter sw = new StreamWriter(this.FullFileName, false, System.Text.Encoding.UTF8);
I've tried many different variations of the System.Text.Encoding classes to save the text file with different encoding types/code pages; but I have not found a way to disable saving the BOM. The strange thing is that at one point this exact code worked as needed (without the BOM), but I cannot figure out what in the system changed to cause my output to be altered.
In a nutshell ...
I need to write a standard 8-bit text file WITH OUT having Byte Order Mark characters at the beginning of the file.
Thank you in advance for your advice.