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

血红的双手。 提交于 2020-06-25 03:58:08

问题


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.


回答1:


From 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.

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

Souce

Using the Download folder

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");  
    }

I hope this can help you.




回答2:


Try this: await file.CopyAndReplaceAsync(cleanFile); await file.RenameAsync("the name you want")



来源:https://stackoverflow.com/questions/36765022/writing-a-file-into-the-downloads-folder-with-uwp-goes-into-isolated-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!