I'm trying to use the FileSavePicker for the first time, but I keep getting an "Unspecified error", with no exception source, when I call await picker.PickSaveFileAsync();
I notice the exceptions data dictionary contains a value 'RestrictedErrorObject-{1F77CB5A-D22F-071F-2637-E6B7C7573653}', so I'm assuming it's permission related somehow.
var picker = new Windows.Storage.Pickers.FileSavePicker();
//picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
//picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Downloads;
//picker.DefaultFileExtension = "csv";
//picker.FileTypeChoices.Add("CSV", new List<string>() { "*.csv" });
picker.SuggestedFileName = fileName;
StorageFile newFile = await picker.PickSaveFileAsync();
So it's now working, I used some code of a Microsoft article (shown below). To be honest I'm struggling to see what the difference was. I definitely didn't need to do anything in the manifest. I used a default extension - but removed the wildcard { ".csv" }
, so that may have been it. But if the wildcard is used you'll get "The parameter is incorrect" exception, which differs from the exceptions I was getting before.
This code works:
var savePicker = new Windows.Storage.Pickers.FileSavePicker();
savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
savePicker.FileTypeChoices.Add("CSV", new List<string>() { ".csv" });
savePicker.SuggestedFileName = fileName;
StorageFile newFile = await savePicker.PickSaveFileAsync();
I solved this error by adding a file type:
picker.FileTypeFilter.Add(".csv");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With