我尝试从我的 Windows 应用程序中读取 xml 文件。在这个中,我在 Assets/Mocks/clubic.xml(构建操作:内容)中添加了一个文件夹,以将 xml 文件中的数据用作模拟。所以我尝试使用以下代码
var package = Windows.ApplicationModel.Package.Current;
var installedLocation = package.InstalledLocation;
try
{
StorageFile sampleFile = await installedLocation.GetFileAsync("Assets/Mocks/clubic.xml");
}
catch (Exception ex)
{
throw ex;
}
try
{
StorageFile sampleFile = await installedLocation.GetFileAsync("ms-appx:///Assets/Mocks/clubic.xml");
}
catch (Exception ex)
{
throw ex;
}
对于这两种情况,我获得了相同的异常 System.ArgumentException: Value does not fall in the expected range。在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() 在 FileReadWrite.MainPage.d__17.MoveNext ()}
我尝试使用此代码
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
if (local != null)
{
// Get the DataFolder folder.
var dataFolder = await local.GetFolderAsync("Assets/Mocks");
// Get the file.
var file = await dataFolder.OpenStreamForReadAsync("clubic.xml");
// Read the data.
using (StreamReader streamReader = new StreamReader(file))
{
this.textBlock1.Text = streamReader.ReadToEnd();
}
}
我仍然遇到同样的问题。你能帮助我吗。
最好的问候,亚历山大