Jaa


FileSavePicker.FileTypeChoices Property

Definition

Gets the collection of valid file types that the user can choose to assign to a file.

public:
 property IMap<Platform::String ^, IVector<Platform::String ^> ^> ^ FileTypeChoices { IMap<Platform::String ^, IVector<Platform::String ^> ^> ^ get(); };
IMap<winrt::hstring, IVector<winrt::hstring> const&> FileTypeChoices();
public IDictionary<string,IList<string>> FileTypeChoices { get; }
var iMap = fileSavePicker.fileTypeChoices;
Public ReadOnly Property FileTypeChoices As IDictionary(Of String, IList(Of String))

Property Value

IMap<String,IVector<String>>

IDictionary<String,IList<String>>

IMap<Platform::String,IVector<Platform::String>>

IMap<winrt::hstring,IVector<winrt::hstring>>

A FilePickerFileTypesOrderedMap object that contains a collection of valid file types (extensions) that the user can use to save a file. Each element in this collection maps a display name to a corresponding collection of file name extensions. The key is a single string, the value is a list/vector of strings representing one or more extension choices.

Examples

The File picker sample demonstrates how to add file type choices with a display name.

FileSavePicker savePicker = new FileSavePicker();
savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
// Dropdown of file types the user can save the file as
savePicker.FileTypeChoices.Add("Plain Text", new List<string>() { ".txt" });
// Default file name if the user does not type one in or select a file to replace
savePicker.SuggestedFileName = "New Document";
auto plainTextExtensions{ winrt::single_threaded_vector<winrt::hstring>() };
plainTextExtensions.Append(L".txt");

savePicker.FileTypeChoices().Insert(L"Plain Text", plainTextExtensions);
savePicker.SuggestedFileName(L"New Document");

If you add multiple FileTypeChoices to the FileSavePicker, the first one added is the default file type. This default will be selected when the user opens the file picker. The default file type is used if the user does not change the file type in the file picker. In this example, the FileTypeChoices entries are added based on which radio button has been selected:

if (radioButtonRichText.IsChecked)
{
    savePicker.FileTypeChoices.Add("Rich text", new List<string>() { ".rtf" });
    savePicker.FileTypeChoices.Add("Word document", new List<string>() { ".docx" });
    savePicker.FileTypeChoices.Add("Plain text", new List<string>() { ".txt" });
}
else if (radioButtonWordDoc.IsChecked)
{
    savePicker.FileTypeChoices.Add("Word document", new List<string>() { ".docx" });
    savePicker.FileTypeChoices.Add("Plain text", new List<string>() { ".txt" });
    savePicker.FileTypeChoices.Add("Rich text", new List<string>() { ".rtf" });
}
else // default to plain text file type
{
    savePicker.FileTypeChoices.Add("Plain text", new List<string>() { ".txt" });
    savePicker.FileTypeChoices.Add("Rich text", new List<string>() { ".rtf" });
    savePicker.FileTypeChoices.Add("Word document", new List<string>() { ".docx" });
}

Remarks

Some apps do not need to understand a file format in order to process it - such as a cloud storage provider. Therefore, using the file wildcard character - "*" - is supported for the FileOpenPicker.FileTypeFilter collection. However, writing a file requires knowledge of its format. As a result, the wildcard is not supported for FileSavePicker.FileTypeChoices.

One display name as a classification of file types might have multiple file types that support it. For example, a display name of "HTML page" could be saved either with ".htm" or ".html" extension. That is why the value of each entry in a FilePickerFileTypesOrderedMap is an ordered list (vector) of strings, displayed in the UI in the order that you place the extensions in the vector.

Applies to

See also