Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I accept any file type in FileSavePicker?

I have an app in which the user can download files. I'm trying to use the FileSavePicker to let him choose the location and file name. The file can be of any type, so I want the FileSavePicker to accept any file type, but apparently I'm not allowed to do this:

picker.FileTypeChoices.Add("All files", new[] { "*" });
// Error: "Ce sélecteur de fichiers n’autorise pas toutes les extensions de fichier."
// (which translates roughly to "This file picker doesn't allow all file extensions")

or this:

picker.FileTypeChoices.Add("All files", new string[0]);
// "Error HRESULT E_FAIL has been returned from a call to a COM component."

Trying to leave FileTypeChoices empty fails as well.

I have added a File Save Picker declaration in my app manifest, and I checked the "Supports any file type" option. EDIT: I just realized this is completely unrelated to my problem...

Is it possible at all to allow any file type? I've been able to do in the FileOpenPicker, using picker.FileTypeFilter.Add("*"), but I can't find a way to do the same with FileSavePicker...

Note: in my case, I already know the original name of the file, so I can use that to create a specific entry in FileTypeChoices, but if the file has no extension, I'm stuck...

like image 890
Thomas Levesque Avatar asked Jun 12 '13 16:06

Thomas Levesque


1 Answers

I'm a little surprised the documentation doesn't cover this at all, but the error message you get when you're trying to use all files filter is pretty clear:

"This file picker does not allow the all files extension."

In other words, no you cannot do this.

As you mentioned, you said you already know the name of the file you're trying to save in most case and you could just set the file type choice to that of the file you're saving. Of course there's the scenario where the file doesn't have an extension as you pointed out, but there's actually a valid "extension" for that as well:

picker.FileTypeChoices.Add("Unknown", new List<string>() { "." });

Hope this helps.

like image 129
dotMorten Avatar answered Nov 03 '22 02:11

dotMorten