![](/img/trans.png)
[英]Windows Forms application for reading and writing a very large XML file, but it is is hanging
[英]Windows 8 xml file writing
我有写入xml文件的问题,放在我的应用程序文件夹中(Windows 8,metro风格)。 当我尝试以读/写模式打开文件时,我收到了Unauthorized AccessException。 我做了很多研究,但仍然没有。 我试过这个解决方案:
var sf = await Package.Current.InstalledLocation.GetFileAsync(@"data.xml");
XmlDocument xmlDoc;
using (var stream = await sf.OpenAsync(FileAccessMode.ReadWrite))
{
xmlDoc = await XmlDocument.LoadFromFileAsync(sf);
XmlElement root = xmlDoc.DocumentElement;
XmlElement xe = xmlDoc.CreateElement("debt");
XmlElement id = xmlDoc.CreateElement("Id");
id.InnerText = Guid.NewGuid().ToString();
XmlElement name = xmlDoc.CreateElement("Name");
name.InnerText = d.Name;
XmlElement surname = xmlDoc.CreateElement("Surname");
surname.InnerText = d.Surname;
xe.AppendChild(id);
xe.AppendChild(name);
xe.AppendChild(surname);
root.AppendChild(xe);
}
if (xmlDoc != null)
await xmlDoc.SaveToFileAsync(sf);
但是,在我正在打开流的行中再次发生异常。
谢谢你的帮助
Package.Current.InstalledLocation.GetFileAsync表示安装应用程序的位置,这是您无法直接写入文件的区域。 使用以下内容
Windows.ApplicationModel.Package.Current.InstalledLocation
要么
Windows.Storage.ApplicationData.Current.LocalFolder.Path
我正在使用前者并且工作正常,请参阅http://metrorssreader.codeplex.com/SourceControl/changeset/view/18082#263004
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.