Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UWP FileSavePicker.PickSaveFileAsync() throws Unspecified error

Tags:

c#

uwp

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();
like image 977
Adrian K Avatar asked Sep 16 '16 22:09

Adrian K


2 Answers

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();
like image 139
Adrian K Avatar answered Nov 20 '22 17:11

Adrian K


I solved this error by adding a file type:

picker.FileTypeFilter.Add(".csv");
like image 35
Jon R Avatar answered Nov 20 '22 17:11

Jon R