Search code examples
xamarinonedrive

unauthorized access exception - access to the path denied - API29


I got access to .txt file located on OneDrive by changing it's path end from =***** to =download. Then I'm trying to download this file using the following code:

            string fileName = Android.OS.Environment.DirectoryDownloads + "/textfile.txt";
            WebClient web = new WebClient();
            web.UseDefaultCredentials = true;
            web.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
            web.DownloadFile(uslugiPath, fileName);

As a result I get this Unauthorized.Access exception (access to Downloads is denied).

I checked [This] (Xamarin : Android : System.UnauthorizedAccessException: Access to the path is denied) topic and many others but I didn't find solution.

Permissins.CheckStatusAsync<Permissions.StorageREad> as a result gives "Granted".

API 29


Solution

  • in my case the solution was use the path defined

    var fileName = global::Android.OS.Environment.ExternalStorageDirectory.AbsolutePath