[英]UWP - Get path to user download folder
I have been looking for a little while now and am not finding much help via MSDN resources and others.我一直在寻找一段时间,并没有通过 MSDN 资源和其他资源找到太多帮助。
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.我知道
DownloadsFolder
类,但是目前不适合我的需要。
How do I get the current user's Download folder path in a Windows Universal App?如何在 Windows 通用应用程序中获取当前用户的下载文件夹路径?
Use Windows.Storage.UserDataPaths
to get the path of user's download folder.使用
Windows.Storage.UserDataPaths
获取用户下载文件夹的路径。
string downloadsPath = UserDataPaths.GetDefault().Downloads;
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
C:\\用户\\用户名\\下载
System.Environment.ExpandEnvironmentVariables("%userprofile%/downloads/")
The DownloadsFolder
for an app now defaults to a folder withing the user's Downloads directory named after the app name (in actual fact the app name folder is simply a link to a folder named after the Package Family Name
) To get the folder name, I used the following hack (vb) to first create a dummy file in the UWP app's DownloadsFolder then using .NET code to get the directory name, and finally deleting the dummy file.应用程序的
DownloadsFolder
现在默认为一个文件夹,其中包含以应用程序名称命名的用户下载目录(实际上,应用程序名称文件夹只是指向以Package Family Name
命名的文件夹的链接)为了获取文件夹名称,我使用下面的hack(vb)首先在UWP应用程序的下载文件夹中创建一个虚拟文件,然后使用.NET代码获取目录名称,最后删除虚拟文件。
Dim o As StorageFile = Await DownloadsFolder.CreateFileAsync("dummy.txt", CreationCollisionOption.GenerateUniqueName)
Dim dirName Ss String = Path.GetDirectoryName(o.Path)
Await o.DeleteAsync(StorageDeleteOption.PermanentDelete)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.