0

This code worked when wanna pick an image in PicturesLibrary:

        ImagePath = string.Empty;
        FileOpenPicker filePicker = new FileOpenPicker();
        filePicker.SuggestedStartLocation = PickerLocationId.**PicturesLibrary**;
        filePicker.ViewMode = PickerViewMode.Thumbnail;

        // Filter to include a sample subset of file types
        filePicker.FileTypeFilter.Clear();
        filePicker.FileTypeFilter.Add(".bmp");
        filePicker.FileTypeFilter.Add(".png");
        filePicker.FileTypeFilter.Add(".jpeg");
        filePicker.FileTypeFilter.Add(".jpg");

        filePicker.PickSingleFileAndContinue();
        view.Activated += viewActivated; 

I created a folder which contained images of my app.

So I'd like to change the location to open: "PicturesLibrary" into "myFolder".

How can I do that?

Thank for reading! Have a beautiful day!

user3688221
  • 87
  • 1
  • 1
  • 7

2 Answers2

0

The ".SuggestedStartLocation" is not supported/functional in windows phone 8.1.

For my camera app i used this:

Inventory all folders in the pictures library:

string savefolder, selectedfilename;

private async void changefolder_button_click(object sender, RoutedEventArgs e)
{
    folderlist_box.Items.Clear();
    IReadOnlyList<StorageFolder> folderlist = await KnownFolders.PicturesLibrary.GetFoldersAsync();
    string folder_read = "";
    foreach (StorageFolder folder in folderlist)
    {
        if (folder.Name != folder_read)
        //Filter duplicate names like "Camera Roll" from libraries on phone and SDCard (if any).
        //Which one is used depends on: Settings -> Storage Sense.
        {
            folder_listbox.Items.Add(folder.Name);
            folder_read = folder.Name;
        }
    }
}

Select the folder you want:

public void folder_listbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    savefolder = folder_listbox.SelectedItem.ToString();
    get_files();
}

Get files in picture library subfolder:

private async void get_files()
{
    file_listbox.Items.Clear();
    StorageFolder currentfolder = await KnownFolders.PicturesLibrary.GetFolderAsync(savefolder);
    IReadOnlyList<StorageFile> filelist = await currentfolder.GetFilesAsync();
    foreach (StorageFile file in filelist)
    {
        file_listbox.Items.Add(file.Name);
    }
}

Select the file:

public void file_listbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    selectedfilename = file_listbox.SelectedItem.ToString();
}
mcb
  • 153
  • 6
0

The FileOpenPicker cannot be suggested to the custom location no matter it's a phone app or windows store app.

The FileOpenPicker is not designed for users to access all folders on the device. Actually, we can treat it as a way to give user the oppotunity to get access to some user awared locations(like the picture library). By default, an app can access certain file system locations. By having the FileOpenPicker or by declaring capabilities, you can access some additional file system locations. So don't expect it will work as the FileOpenDialog we previously used for windows desktop app.

Something I do agree in mcb's answer is the suggested method to access the sub folders(or your app's local storage folder) that is using a list to show the folder list or file list to enable user access it.

Something I cannot agree in mcb's answer is "The ".SuggestedStartLocation" is not supported/functional in windows phone 8.1.". That is not the truth, it should be supported by windows phone 8.1 but not all options work on the phone.

Alan Yao - MSFT
  • 3,284
  • 1
  • 17
  • 16