I try to download file from web and save to any of Environment.SpecialFolder locations. No matter of what approach I try - I always get
System.UnauthorizedAccessException: 'Access to the path 'any possible path I try (even beyond Environment.SpecialFolder)' is denied.'
I tried accessing filesystem on UWP and Android - both same exception.
What I tried with no luck so far:
Code sample:
var webClient = new WebClient();
webClient.DownloadDataCompleted += (s, e) => {
var bytes = e.Result;
string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
string localFilename = "downloaded.jpg";
string localPath = Path.Combine(documentsPath, localFilename);
File.WriteAllBytes(localPath, bytes);
};
webClient.DownloadDataAsync(new Uri(url));