【发布时间】:2012-08-11 00:16:25
【问题描述】:
如果现有的 xml 文件已经存在,我正在尝试覆盖它。
我正在使用下面的代码来检查文件是否存在,如果存在则覆盖它。现有文件是隐藏的,所以我在尝试覆盖之前取消隐藏它。
文件没有发生更改,但是覆盖不起作用。
这是我在下面使用的代码减去我正在编写新的 xml 数据的部分。
if(File.Exists(filePath))
{
File.SetAttributes(filePath,FileAttributes.Normal);
FileIOPermission filePermission =
new FileIOPermission(FileIOPermissionAccess.AllAccess,filePath);
FileStream fs = new FileStream(filePath, FileMode.Create);
XmlWriter w = XmlWriter.Create(fs);
}
【问题讨论】:
-
您编写新 xml 数据的部分在这里似乎很重要......
标签: c# xml filestream file-permissions