UWP FileSavePicker.PickSaveFileAsync() throws Unspecified error
Asked Answered
B

2

7

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();
Borrego answered 16/9, 2016 at 22:2 Comment(2)
Have you tried to add default file extension? I think that pickers do crash without it, at least I am sure for open file picker.Renie
@AdrianK Maybe you Need to add some capabilities in the AppManifestDdt
B
9

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();
Borrego answered 18/9, 2016 at 5:20 Comment(1)
I ran into the same issue. I think the line for FileTypeChoices.Add is what's "fixing" it.Polley
T
2

I solved this error by adding a file type:

picker.FileTypeFilter.Add(".csv");
Taken answered 2/7, 2020 at 21:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.