积极答复者
UWP应用如何获取往任意路径写入文件的权限

问题
全部回复
-
也不是所有文件夹都没权限,像音乐库、图片图或者自己工作的文件夹当然是有权限,但是当用户选择的是D:\新建文件夹 这种路径,就没权限了。
public async Task HandleDownload(string title, string url) { string filename; if (string.IsNullOrEmpty(DownloadFolder.Path)) filename = "C:\\Users\\BILL\\Music\\" + title + ".mp3"; else filename = DownloadFolder.Path + "\\"+ title + ".mp3"; try { await Task.Run(() => WebSongProxy.DownloadSong(url, filename)); StorageFile file = await StorageFile.GetFileFromPathAsync(filename); await AddDownloadedSong(file); } catch (HttpRequestException ex) { FileStream fs = new FileStream(".//log.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite); using (StreamWriter sw = new StreamWriter(fs)) { string content = ex.Message; sw.Write(content + DateTime.Now.ToString()); } throw; } //catch (Exception ex) //{ // FileStream fs = new FileStream(".//log.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite); // using (StreamWriter sw = new StreamWriter(fs)) // { // string content = ex.Message; // sw.Write(content + DateTime.Now.ToString()); // } //} }
其中DownloadFolder是用FolderPicker选择的文件夹。