如何在Windows应用商店应用中允许使用File Picker?

时间:2014-03-01 14:13:11

标签: c# .net xaml windows-store-apps visual-studio-2013

使用c#,Windows Store App,VS 2013

尝试使用下一个简单代码打开文件选择器:

    private async void OkBtnClick(IUICommand command)
    {
        if (this.EnsureUnsnapped())
        {
            FileOpenPicker fop = new FileOpenPicker();
            fop.FileTypeFilter.Add(".png");
            fop.FileTypeFilter.Add(".jpg");
            fop.FileTypeFilter.Add(".jpeg");
            fop.ViewMode = PickerViewMode.Thumbnail;

            fop.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            StorageFile requestedFile = await fop.PickSingleFileAsync();

            if (requestedFile != null)
            {
             //TODO:
            }
        }
    }

    internal bool EnsureUnsnapped()
    {
        // FilePicker APIs will not work if the application is in a snapped state.
        // If an app wants to show a FilePicker while snapped, it must attempt to unsnap first
        bool unsnapped = ((ApplicationView.Value != ApplicationViewState.Snapped) 
            || ApplicationView.TryUnsnap());
        if (!unsnapped)
        {
            Extensions.NotifyUser("Cannot unsnap app...", statusNotificationBlock);
        }

        return unsnapped;
    }

还在图片库的appmanifest文件中添加功能:

enter image description here

但在跑步过程中遇到异常:System.UnauthorizedAccessExceptionStorageFile requestedFile = await fop.PickSingleFileAsync();行。

问题:如果提供了所有必需的访问权限,为什么我会收到此异常,另外我尝试使用管理员权限启动VS2013 - 结果 - 同样。


要创建此代码,请使用this article

0 个答案:

没有答案