Beispiel #1
0
        private async Task <StorageFile?> DownloadPickerPickSaveFileAsync(CancellationToken token)
        {
            if (SuggestedSaveFile == null)
            {
                var temporaryFolder = ApplicationData.Current.LocalCacheFolder;
                if (!Directory.Exists(temporaryFolder.Path))
                {
                    temporaryFolder.MakePersistent();
                }

                if (string.IsNullOrEmpty(SuggestedFileName))
                {
                    SuggestedFileName = Guid.NewGuid().ToString();
                }

                var extension = FileTypeChoices.Count > 0 ? FileTypeChoices.First().Value[0] : "";

                // The mime type is chosen by the extension, and we cannot reliably send multiple mime type in the browser
                var fileName = SuggestedFileName + extension;
                SuggestedSaveFile = await temporaryFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

                SuggestedSaveFile.ProviderOverride = StorageProviders.WasmDownloadPicker;
            }
            return(SuggestedSaveFile);
        }
Beispiel #2
0
 private async Task <StorageFile?> DownloadPickerPickSaveFileAsync(CancellationToken token)
 {
     if (SuggestedSaveFile == null)
     {
         var temporaryFolder = ApplicationData.Current.LocalCacheFolder;
         if (!Directory.Exists(temporaryFolder.Path))
         {
             temporaryFolder.MakePersistent();
         }
         // The mime type is chosen by the extension, and we cannot reliably send multiple mime type in the browser
         var fileName = SuggestedFileName + FileTypeChoices.First().Value[0];
         SuggestedSaveFile = await temporaryFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
     }
     return(SuggestedSaveFile);
 }