I have these permissions in the Android Manifest file
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
also requesting permission at runtime.
Here is my pdf download code
var documentsPath = (string)Android.OS.Environment.GetExternalStoragePublicDirectory("SHAZ");
string localPath = Path.Combine(documentsPath, filename);
File.WriteAllBytes(localPath, bytes);
Here is what I am getting from the android app.
** {System.UnauthorizedAccessException: Access to the path "/storage/emulated/0/SHAZ/ABC.pdf" is denied. at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x001aa] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.IO/FileStream.cs:239 at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.IO/FileStream.cs:91 at (wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare) at System.IO.File.InternalWriteAllBytes (System.String path, System.Byte[] bytes) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.IO.FileSystem/src/System/IO/File.cs:429 at System.IO.File.WriteAllBytes (System.String path, System.Byte[] bytes) [0x00039] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.IO.FileSystem/src/System/IO/File.cs:420 at SHAZ_HR_Payroll.Droid.Models.SaveFile.SaveFiles (System.String filename, System.Byte[] bytes) [0x00034] in SaveFile.cs:25 at SHAZ_HR_Payroll.Pages.Employee.EmployeeChangePasswrod.BtnDownload_Clicked (System.Object sender, System.EventArgs e) [0x000d7] in \XYZ.xaml.cs:84 } **
IDE: VS-2019 Android Version: 10 Xamarin Form Version: 5.0.0.1874