UWP - Get path to user download folder

南笙酒味 提交于 2020-01-13 12:55:32

问题


I have been looking for a little while now and am not finding much help via MSDN resources and others.

My predicament is simple: my app needs a base directory to the Downloads folder. I am aware of the DownloadsFolder class however that is not suiting my needs currently.

How do I get the current user's Download folder path in a Windows Universal App?


回答1:


Is that what you need?

string localfolder = ApplicationData.Current.LocalFolder.Path;
var array = localfolder.Split('\\');
var username = array[2];
string downloads = @"C:\Users\" + username + @"\Downloads";

This will result

C:\Users\username\Downloads




回答2:


Use Windows.Storage.UserDataPaths to get the path of user's download folder.

string downloadsPath = UserDataPaths.GetDefault().Downloads;
  • This method is introduced in build 16232, so clients with RS3(1709) or later will be able to run it.
  • You shouldn't obtain downloads folder path using LocalFolder, which might result in wrong folder when the user changed the default location for it.



回答3:


System.Environment.ExpandEnvironmentVariables("%userprofile%/downloads/")


来源:https://stackoverflow.com/questions/39949829/uwp-get-path-to-user-download-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!