[英]Writing/Reading To/From File Windows 8.1 AppStore App
I have a Windows 8.1 App from which I want to write to and read from an XML file that is put in the "Assets" folder in the Application package. 我有一个Windows 8.1应用程序,我要从其中写入和读取XML文件,该文件位于应用程序包的“资产”文件夹中。
I call the following method from the page constructor after the this.InitializeComponent();
我在this.InitializeComponent();
之后从页面构造函数调用以下方法this.InitializeComponent();
line: 线:
private async void ReadXML()
{
var uri = new System.Uri("ms-appdata:///Assets/gameInfo.xml");
StorageFile file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri);
XmlDocument reader = new XmlDocument();
reader.LoadXml(file.ToString());
XmlNodeList nodes = reader.DocumentElement.ChildNodes;
string attr = nodes[0].Attributes[0].InnerText;
int bestTime;
if (attr != null && int.TryParse(attr, out bestTime))
BestTime = bestTime;
}
When I navigate to the page that contains this code and it runs I get an ArgumentException thrown on the StorageFile file...
line. 当我导航到包含此代码的页面并运行时,我在StorageFile file...
行上抛出ArgumentException。 Here is the exception detail: 这是异常详细信息:
System.ArgumentException was unhandled by user code
HResult=-2147024809
Message=Value does not fall within the expected range.
Source=mscorlib
StackTrace:
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at LightsOutApp.Random4x4.<ReadXML>d__0.MoveNext()
InnerException:
Does anyone have any idea why this exception is being thrown? 有谁知道为什么会引发此异常? Thank you for any help. 感谢您的任何帮助。
I tried doing ms-app in stead of ms-appdata and it fixed that error. 我尝试执行ms-app而不是ms-appdata,它修复了该错误。 Thank you for your help. 谢谢您的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.