gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 01:16:04 24 4
gpt4 key购买 nike

我需要在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com