I want to create an XML file to store information. I am using the following code. I would like to know how to specify the encoding for this file in code.
When I try to r
You are using the overload of the Save method that takes a file name as a parameter. This method uses the UTF-8 encoding. Create an xml declaration before you create the root:
// ...
XmlDeclaration documentType = writer.CreateXmlDeclaration("1.0", "utf-8", null);
writer.AppendChild(documentType);
XmlElement root = writer.CreateElement("PatientFile");
writer.AppendChild(root);
// ...
As a side note, if you want to have control over the encoding that the file is created with, you need to use one of the other overloads of the Save method.