locked
How to access the file programmatically from D:?

    Question

  • Hi Experts,

    In my application i need access the file from D: by programmatically not by using file pickers. But when i try to access the file i got "Access Denied Exception". Please help me on this.

    Thanks in advance.

    Regards,

    Riyaj Ahamed I

    Thursday, May 29, 2014 2:42 PM

Answers

  • Hi Manos,

    That would be a different problem.

    Apps don't have access to arbitrary file locations like D:\ and so will always get an access denied when trying to directly use them.

    Your app wasn't running into a persistent access denied: it had access to the location and could use the files. What it ran into was a sharing violation: the file was already locked an in use, so the app couldn't open a new reference to it. Disposing the stream will close and unlock the file so a new stream can be opened, but that only works because the app could read the file in the first place.

    --Rob

    Thursday, May 29, 2014 9:18 PM
    Owner

All replies

  • Why do you need this? What is the scenario?

    You cannot. You're app doesn't have access to the file system outside of its app data directories without user permission via file pickers or equivalents.

    Once picked the app can cache the access for later with the AccessCache classes so it doesn't need to use the pocket the next time

    Thursday, May 29, 2014 3:32 PM
    Owner
  • Few days ago, I came across a similar problem. There was a piece of code that was accessing a file in the local storage in order to wright in it. However, the stream used, was never disposed. Every attempt to access any file after that code run was resulting in the exception you mentioned. I don't know if that helps, but maybe its worth looking into.

    Rgds,

    Manos


    Thursday, May 29, 2014 9:03 PM
  • Hi Manos,

    That would be a different problem.

    Apps don't have access to arbitrary file locations like D:\ and so will always get an access denied when trying to directly use them.

    Your app wasn't running into a persistent access denied: it had access to the location and could use the files. What it ran into was a sharing violation: the file was already locked an in use, so the app couldn't open a new reference to it. Disposing the stream will close and unlock the file so a new stream can be opened, but that only works because the app could read the file in the first place.

    --Rob

    Thursday, May 29, 2014 9:18 PM
    Owner