[英]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?使用 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.
我知道我可以使用 FilePicker 选择要在我的应用程序中使用的文件,但我实际上想做相反的事情,将我的应用程序中的文件保存在某个地方,或者只是将其放入下载中。
This is an example saving the StoreLogo.png file, which is in the Assets folder by default, to the Downloads folder.这是将 StoreLogo.png 文件(默认情况下位于 Assets 文件夹中)保存到 Downloads 文件夹的示例。
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.