user5193098
user5193098

Reputation:

How can I write XML in UTF8 instead of UTF8 without a BOM?

My tool creates an XML file upon button press; however, it is UTF8 without BOM. How can I ensure it is created in simple UTF8?

My code is:

StreamWriter File = new StreamWriter(folderpath.Text + "\\folder\\setup_file.xml");
       File.Write(textboxON.Text);
       File.Close();

Upvotes: 1

Views: 422

Answers (2)

user5193098
user5193098

Reputation:

True value was needed in:

StreamWriter File = new StreamWriter(srcPath.Text + "\\Destination\\setup.xml", true, Encoding.UTF8, 512);
            File.Write(toAdd.Text);
            File.Close();

Upvotes: 0

themattkellyshow
themattkellyshow

Reputation: 161

To force a specific encoding, simply pass it in as the second argument of your constructor. More information can be found here.

StreamWriter File = new StreamWriter(folderpath.Text + "\\folder\\setup_file.xml", Encoding.UTF8);

You can also pass in your buffer size as the third argument, but I don't think you will have to worry about it in your case.

Upvotes: 2

Related Questions