1

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();
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Andreas Ward
  • 121
  • 9

2 Answers2

3

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.

0

True value was needed in:

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