Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 加载OneDrive文档_C#_.net_Windows Store Apps_Windows Store_Onedrive - Fatal编程技术网

C# 加载OneDrive文档

C# 加载OneDrive文档,c#,.net,windows-store-apps,windows-store,onedrive,C#,.net,Windows Store Apps,Windows Store,Onedrive,我正在开发一个Windows应用商店应用程序。我有一个OneDrive文档的路径。我尝试使用以下方法打开它: await StorageFile.GetFileFromPathAsync(path); 我知道该文件存在,因为我可以导航到它C:\Users\User\OneDrive\Documents\Example.txt,但由于某些原因,等待GetFileFromPathAsync总是引发异常。我从主页构造函数中调用的函数调用此代码,如下所示: public MainPage() {

我正在开发一个Windows应用商店应用程序。我有一个OneDrive文档的路径。我尝试使用以下方法打开它:

await StorageFile.GetFileFromPathAsync(path);
我知道该文件存在,因为我可以导航到它C:\Users\User\OneDrive\Documents\Example.txt,但由于某些原因,等待GetFileFromPathAsync总是引发异常。我从主页构造函数中调用的函数调用此代码,如下所示:

public MainPage()
{
    ...
    LoadFile("C:\\Users\\User\\OneDrive\\Documents\\Example.txt");
    ...
}

private async void LoadFile(string path)
{
    await StorageFile.GetFileFromPathAsync(path);
}

有什么问题?

有什么例外?@ChiefTwoPencils刚刚用try-catch语句包装了它;它表示异常为System.UnauthorizedAccessException:访问被拒绝。但是,我不知道这是怎么回事,也不知道我错过了什么。是因为我没有使用文件选择器吗?我在网上读到,如果我攻击清单的应用程序功能以添加文档功能,应用程序将不会被批准…因此,没有标准方法保存使用的最后一个文件路径并在启动时再次加载它?这回答了我的问题: