0

I am working on a Windows Store app. I have a path to a OneDrive document. I try to open it using:

await StorageFile.GetFileFromPathAsync(path);

I know the file is present, as I can navigate to it (C:\Users\User\OneDrive\Documents\Example.txt), but for some reason awaiting GetFileFromPathAsync always throws an exception. I am calling this code from a function which is called within my MainPage constructor, something like this:

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

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

What is the problem?

Alexandru
  • 12,264
  • 17
  • 113
  • 208
  • What's the exception? – ChiefTwoPencils Oct 21 '14 at 02:19
  • @ChiefTwoPencils Just wrapped a try-catch statement around it; it says the exception is "System.UnauthorizedAccessException: Access is denied." But, I'm not sure how this can be, or what I am missing. Is it because I'm not using the file picker? I read online that apps won't be approved if I hack the manifest's app capabilities to add the documents capability...so there is no standard way to save the last file path used and load it again on startup? – Alexandru Oct 21 '14 at 02:21
  • 1
    This answered my question: http://stackoverflow.com/questions/26478074/how-to-automatically-load-previously-used-files-on-windows-store-app-startup – Alexandru Oct 21 '14 at 03:40

0 Answers0