我正在开发Windows应用商店应用。我有一个OneDrive文档的路径。我尝试使用以下方式打开它:
await StorageFile.GetFileFromPathAsync(path);
我知道该文件存在,因为我可以导航到它(C:\Users\User\OneDrive\Documents\Example.txt
),但由于某种原因等待GetFileFromPathAsync
总是抛出异常。我从我的MainPage
构造函数中调用的函数调用此代码,如下所示:
public MainPage()
{
...
LoadFile("C:\\Users\\User\\OneDrive\\Documents\\Example.txt");
...
}
private async void LoadFile(string path)
{
await StorageFile.GetFileFromPathAsync(path);
}
有什么问题?