使用 UWP 将文件写入下载文件夹会进入独立存储吗? [英] Writing a file into the Downloads folder with UWP goes into Isolated Storage?

查看:24
本文介绍了使用 UWP 将文件写入下载文件夹会进入独立存储吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 Windows 10 上的 UWA 的下载文件夹中创建一个文件,并将现有文件的内容复制到其中.我使用以下代码:

I need to create a file in the downloads folder for a UWA on Windows 10 and copy the content of an existing file into it. I use the following code:

StorageFile cleanFile = await Windows.Storage.DownloadsFolder.CreateFileAsync(cleanFileName);

await file.CopyAndReplaceAsync(cleanFile);

这没问题,但文件存储的文件夹是这样的:

This works ok, but the folder the file is stored is this:

C:\Users\MyUser\Downloads\e15e6523-22b7-4188-9ccf-8a93789aa8ef_t8q2xprhyg9dt!App\WordComment-clean.docx

我认为这是某种类型的隔离存储.但实际上,这不是我需要的.由于用户无法看到这样的文件.

I assume this is some type of Isolated Storage. But really, that is not what I need. Since the user can't see the file like this.

推荐答案

来自 MSDN:

用户的下载文件夹.默认保存下载文件的文件夹.

User’s Downloads folder. The folder where downloaded files are saved by default.

默认情况下,您的应用只能访问您的应用创建的用户下载文件夹中的文件和文件夹.但是,您可以通过调用文件选择器(FileOpenPicker 或 FolderPicker)来访问用户下载文件夹中的文件和文件夹,以便用户可以导航并选择您的应用要访问的文件或文件夹.>

By default, your app can only access files and folders in the user's Downloads folder that your app created. However, you can gain access to files and folders in the user's Downloads folder by calling a file picker (FileOpenPicker or FolderPicker) so that users can navigate and pick files or folders for your app to access.

如果您不使用文件选择器,则您会将文件保存在下载"中的应用文件夹中.

If you don't use a file picker, you are saving the file in your app folder in Downloads.

来源

使用下载文件夹,用户需要手动选择下载文件夹.

For using the download folder, the user needs to select the download folder manually.

FolderPicker picker = new FolderPicker { SuggestedStartLocation = PickerLocationId.Downloads };
    picker.FileTypeFilter.Add("*");
    StorageFolder folder = await picker.PickSingleFolderAsync();
    if (folder != null) {
           await folder.CreateFileAsync("Hello1.txt");  
    }

希望能帮到你.

这篇关于使用 UWP 将文件写入下载文件夹会进入独立存储吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆