简单的问题,我如何用xmltextwriter覆盖?
我使用var writer = new XmlTextWriter(exam.Path, null);
。
所以,如果我有一个新的文件,它就像我应该写的那样。
但是如果文档已经存在,我该如何用新文档覆盖这个文档?
答案 0 :(得分:3)
documentation表示您的使用将截断文件并用新内容覆盖它。
filename类型:System.String 要写入的文件名。如果是文件 存在,它会截断它并覆盖它 它带有新内容。
答案 1 :(得分:0)
如果您想覆盖该文件并找到当前附加的方法,您可以尝试事先删除相关文件。
e.g。
System.IO.File.Delete(exam.Path);
var writer = new XmlTextWriter(exam.Path, null);