I'm getting the UnauthorizedAccessException when starting up my emulator with my application, it tells me that "Access to /storage/emulated/0/Download/MenuPlayer is denied".
This only occurs when I try to create a file or open up a folder to download files into it.
My AndroidManifest.xml code is:
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="26" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> My Code that is trying to access this is:
try { /// Get the path to the downloads folder var donwloadDir = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads); path = Path.Combine(donwloadDir.AbsolutePath, dirName); dirInfo = new DirectoryInfo(path); ///Create a path to the config file folder. configFilePath = Android.OS.Environment.GetExternalStoragePublicDirectory("").AbsolutePath + "/"; } catch(Exception e) { Android.Util.Log.Debug(TAG, "STUFF HERE..." + configFilePath); Android.Util.Log.Debug(TAG, e.Message); System.IO.File.WriteAllText(@"C:\logs.txt", e.Message); } System.IO.File.WriteAllText(@"C:\logs.txt", Android.OS.Environment.DirectoryDownloads); Android.Util.Log.Debug(TAG, configFilePath); Android.Util.Log.Debug(TAG, "END | PlayerReader"); the error is:
Unhandled Exception:
System.UnauthorizedAccessException: Access to the path "/storage/emulated/0/Download/MenuPlayer" is denied. occurred