开发者

How to handle Illegal Chars in XML

开发者 https://www.devze.com 2023-01-12 11:07 出处:网络
How should I handle this situation? I set the Encoding to UTF8 but I still get errors... I create that string (that I set to the WebBrowser.DocumentText) from a Mem开发者_运维知识库oryStream obj

How should I handle this situation?

I set the Encoding to UTF8 but I still get errors...

How to handle Illegal Chars in XML

I create that string (that I set to the WebBrowser.DocumentText) from a Mem开发者_运维知识库oryStream object and I'm ending it like this:

Byte[] buffer = new Byte[ms.Length];
buffer = ms.ToArray();
return System.Text.Encoding.UTF8.GetString(buffer);

What am I missing?


You're passing the XML string as a filename.

You probably want to write

File.WriteAllText(saveFileDialog.FileName, wb.DocumentText);

Or, alternatively,

using(StreamWriter writer = new StreamWriter(saveFileDialog.OpenFile(), false, Encoding.UTF8)) {
    write.Write(wb.DocumentText);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号