FileSavePicker in Windows 8 XAML App


In the previous article we have seen the features of FileOpenPicker. In this article we would see the FileSavePicker which is in Windows 8. We have SaveFileDialog in WPF/Silverlight, but in case of WinRT it’s not there; replaced by FileSavePicker.

Get Started

Create the instance of FileSavePicker. It requires “Windows.Storage.Pickers” to be referenced.

We need to make a point for from which location it should start.

So we have SuggestedStartLocation, which has many options. In this sample we would save into Documents Library.

FileTypeChoices is one of the mandatory property, where we have mention the extension of the file we are going to save. Keep in memory that, we have to give the extension only. While displaying it automatically displays the Description.

For example:

If we are providing “.txt” or “.TXT”, the display would be “Text (.txt)”.

So you go the idea, now let’s add two entries into the FileTypeChoices.

Again, the FileTypeChoices property is read only dictionary, so we could only add to it.

Now we would open the picker, which is awaitable.

So we need to add the event/method as async capable.

The following file NULL check is required; as in FilePicker we have Cancel operation, which would not create the file but returns the file as NULL.

And we would write to the File. In this sample I am writing a text file, so I am using the WriteTextAsync method.

Let’s see it in running.

The FilePicker starts with the location that we have mentioned, and provide a name and click on save, saves the file.

If the file already exists, it pops up the message to replace.

Also we have options for saving other file types, as we discussed earlier.

Let’s check the file in Documents Library. Yes, we have successfully created files using FileSavePicker.



Source Code: Click Here

Article as PDF: Click Here

Related Posts:

1) Data Template Selector in Windows 8 Metro XAML App

2) FileOpenPicker in Windows 8 XAML App

3) Save as Image in Picture Library in Windows 8 XAML Metro App

4) Remove Windows 8 from your Dual-Boot Setup