我尝试从网络下载文件并保存到任何 Environment.SpecialFolder 位置。无论我尝试什么方法 - 我总是得到
System.UnauthorizedAccessException: '访问路径'我尝试的任何可能的路径(甚至超出 Environment.SpecialFolder)'被拒绝。
我尝试在 UWP 和 Android 上访问文件系统 - 都是相同的例外。
到目前为止我没有运气的尝试:
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));
Run Code Online (Sandbox Code Playgroud)