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

Writing a file into the Downloads folder with UWP goes into Isolated Storage?

我需要在 Windows10 上的 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

使用下载文件夹

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

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

希望对您有所帮助

试试这个: 等待file.CopyAndReplaceAsync(cleanFile); 等待 file.RenameAsync("the name you want")