简体   繁体   中英

How to save a file to downloads using WinUI 3?

How do I save a file generated by my application to the downloads folder when using the WinUI 3 SDK? I know I can use FilePicker to select a file to use in my application but I would like to essentially do the opposite and save a file from my application somewhere or just simply put it into downloads.

This is an example saving the StoreLogo.png file, which is in the Assets folder by default, to the Downloads folder.

using Windows.Storage;
...

// Get the StoreLogo.png file as a StorageFile.
Uri storeLogoUri = new($"ms-appx:///Assets/StoreLogo.png");
StorageFile storeLogoFile = await StorageFile.GetFileFromApplicationUriAsync(storeLogoUri);

// Get the Downloads folder as a StorageFolder.
string downloadsFolderPath = UserDataPaths.GetDefault().Downloads;
StorageFolder downloadsFolder = await StorageFolder.GetFolderFromPathAsync(downloadsFolderPath);

// Save (copy) the StoreLogo.png file.
await storeLogoFile.CopyAsync(downloadsFolder);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM