?
Solved

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

Posted on 2010-01-11
1
Medium Priority
?
695 Views
Last Modified: 2012-05-08
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.
0
Comment
Question by:mdtanner
1 Comment
 
LVL 10

Accepted Solution

by:
krunal_shah earned 2000 total points
ID: 26290202
Hi,
Please check the following link, it may help you

http://vbnotebookfor.net/2007/05/26/beware-of-the-byte-order-mark/
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question