The following hunk of code (snipped for brevity) generates an xml doc, and spits it out to a file. If I open the file in Visual Studio it appears to be in chinese characters. If I open it in Notepad it looks as expected. If I Console.WriteLine it look correct.
I know it's related to encoding, but I though I had all the encoding ducks in a row. What's missing?
StringBuilder stringBuilder = new StringBuilder();
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.Unicode;
settings.Indent = true;
settings.IndentChars = "\t";
using (XmlWriter textWriter = XmlWriter.Create(new StringWriter(stringBuilder), settings))
{
textWriter.WriteStartElement("Submission");
textWriter.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
textWriter.WriteEndElement();
}
using (StreamWriter sw = new StreamWriter(new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None)))
{
sw.Write(stringBuilder.ToString());
}