locked
openasync api raises exception when open a file from onedrive

    Question

  • Hi,
    I have created a C# Windows store app, In my app I am opening a file from OneDrive by using file picker. After pressing the open button from file picker, I have the below code

    IRandomAccessStream imageFileRAStream = await file.OpenAsync(FileAccessMode.Read);

    Here OpenAsync API raises the below exception and unable to sets the source image for a BitmapSource.

    Error HRESULT E_FAIL has been returned from a call to a COM component.

    Kindly help in resolving this issue.

    Ashok

    Thursday, September 25, 2014 10:04 AM

All replies

  • Hi ashok,

    Could you validate if there are some other applications using your target file? You can also try with a local folder to see if the same thing happens.

    Use OpenReadAsync instead might be a good choice.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, September 26, 2014 4:57 AM
    Moderator
  • Hi James,

    Thanks for the reply. I have tried by opening a file from local folder using file picker. After pressing the open button from file picker the below code does not raises any exception.

    IRandomAccessStream imageFileRAStream = await file.OpenAsync(FileAccessMode.Read);

    I have tried OpenReadAsync as per your suggestion and the same exception is raised as mentioned earlier.

    Kindly help in resolving this issue.

    Ashok

    Friday, September 26, 2014 6:46 AM
  • Hi ashok,

    Looks like file picker works fine but select from OneDrive folder cause the problem.

    I test following code with my OneDrive folder but everything works fine, I do not see any exception has been thrown. Could you double check if you have some setting on your OneDrive or the file you want to select is being used by some other application(for instance is being sync by onedrive), or you could even double check your setting on OneDrive (might be a possibility)

            private async void Button_Click_1(object sender, RoutedEventArgs e)
            {
                FileOpenPicker picker = new FileOpenPicker();
                picker.FileTypeFilter.Add(".zip");
                StorageFile file = await picker.PickSingleFileAsync();
                IRandomAccessStream imageFileRAStream = await file.OpenAsync(FileAccessMode.Read);
            }

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, September 26, 2014 9:01 AM
    Moderator
  • Hi James,

    Thanks for the reply. I have verified the Sync settings, all are OK. But still this issue is reproducible.

    I have verified this in another 2 PCs, the issue is not occurred in one PC and occurred in another PC.

    Kindly advice.

    Ashok

    Friday, September 26, 2014 12:39 PM
  • Hi Ashok,

    Maybe double check if you have the same update installed? I cannot reproduce the issue here.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Sunday, September 28, 2014 7:40 AM
    Moderator