c# - 使用 UWP 将文件写入“下载”文件夹会进入独立存储吗?

标签 c# win-universal-app isolatedstorage

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

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

await file.CopyAndReplaceAsync(cleanFile);

这工作正常,但文件存储的文件夹是这样的:

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

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

最佳答案

来自 MSDN:

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

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.

如果您不使用文件选择器,则文件将保存在“下载”中的应用文件夹中。

Souce

使用下载文件夹

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

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

希望对您有所帮助。

关于c# - 使用 UWP 将文件写入“下载”文件夹会进入独立存储吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36765022/

相关文章:

c# - IDictionary 和 IReadOnlyDictionary 的扩展方法

C# 套接字 : accept a socket, 忽略它的消息,发回一个

c# - 如何使用 Cake 脚本执行 t4 模板

xaml - Visual Studio 2013 更新 3,设计器不会加载

silverlight-4.0 - 银光 4.0 : IsolatedStorage URI

c# - 即使应用程序关闭,如何在 Windows Phone 的 IsolatedStorageSettings 中保留数据?

c# - 有没有办法让网络服务器(不是简单的客户端)向客户端应用程序发送消息?

entity-framework - 在通用应用程序中使用 EF7 实现数据库优先

c# - 自适应触发器和数据模板

c# - 在 Windows Phone 8 中读取和写入列表到 IsolatedStorage