简体   繁体   English

FilePicker Windows Phone 8.1

[英]FilePicker Windows Phone 8.1

This code worked when wanna pick an image in PicturesLibrary: 想在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". 因此,我想更改打开位置:将“ PicturesLibrary”更改为“ myFolder”。

How can I do that? 我怎样才能做到这一点?

Thank for reading! 感谢阅读! Have a beautiful day! 祝你今天过得愉快!

The " .SuggestedStartLocation " is not supported/functional in windows phone 8.1. Windows Phone 8.1不支持“ .SuggestedStartLocation ”功能。

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();
}

The FileOpenPicker cannot be suggested to the custom location no matter it's a phone app or windows store app. 无论是电话应用程序还是Windows应用商店应用程序,都无法将FileOpenPicker推荐给自定义位置。

The FileOpenPicker is not designed for users to access all folders on the device. FileOpenPicker不适用于用户访问设备上的所有文件夹。 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. 通过具有FileOpenPicker或声明功能,可以访问一些其他文件系统位置。 So don't expect it will work as the FileOpenDialog we previously used for windows desktop app. 因此,不要指望它会像我们以前用于Windows桌面应用程序的FileOpenDialog一样起作用。

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. 我确实同意mcb的回答,这是建议的访问子文件夹(或应用程序的本地存储文件夹)的方法,该方法使用列表显示文件夹列表或文件列表以使用户能够访问它。

Something I cannot agree in mcb's answer is "The ".SuggestedStartLocation" is not supported/functional in windows phone 8.1.". 我在mcb的答案中无法达成共识的是“ Windows Phone 8.1中不支持“ .SuggestedStartLocation”。 That is not the truth, it should be supported by windows phone 8.1 but not all options work on the phone. 事实并非如此,Windows Phone 8.1应该支持它,但并非所有选项都可以在手机上使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM