Link to home
Start Free TrialLog in
Avatar of mdtanner
mdtanner

asked on

Write text file in ASP.Net - C# without Byte Order Mark

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);
sw.Write(StringToWrite);
sw.Close();

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.
ASKER CERTIFIED SOLUTION
Avatar of krunal_shah
krunal_shah

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial