FilePicker Vs StorageFile RRS feed

  • Question

  • We can create an empty file( eg:Sample.jpg) in pictures folder as follows:


      StorageFile tmp = await KnownFolders.PicturesLibrary.CreateFileAsync("Sample.jpg", CreationCollisionOption.ReplaceExisting);

    We can also accomplish similar thing using FilePicker as follows:

     FileSavePicker savePicker = new FileSavePicker();
                savePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                savePicker.FileTypeChoices.Add("JPG file", new List<string>() { ".jpg" });
                savePicker.SuggestedFileName = "Sample.jpg"
                StorageFile file = await savePicker.PickSaveFileAsync();
    Both creates an empty file Sample.jpg in PicturesFolder. Is there any difference in the format of file being created in two cases? Does these two ways accomplish the same thing? If I go for the first way, can I avoid displaying file picker?

    • Edited by its_me_here Saturday, January 26, 2013 8:27 PM
    Saturday, January 26, 2013 8:25 PM


  • Both files are exactly the same.

    The only difference is that :

    With the first option (using the PicturesLibrary), you will have to declare the Pictures Library capability. You don't need to display a filepicker with this option, you can do it without requesting any user input because the user already grants your app the necessary rights.

    With the second option (PickSaveFileAsync), the user will select the file by himself. You have to display the PickSaveFile UI, but you don't need to declare the Pictures Library capability.


    • Proposed as answer by Can Bilgin Sunday, January 27, 2013 8:03 AM
    • Marked as answer by Aaron Xue Monday, February 4, 2013 7:06 AM
    Sunday, January 27, 2013 12:16 AM