Sea*_*ary 5 c# comexception uwp
我正在尝试制作一个通用应用程序,该应用程序仅打开一个文件夹(如快捷方式),但允许使用自定义颜色和更大的图标进行新的开始磁贴设计。
当我打开FolderPicker授予应用程序访问目录的权限时,出现错误,我也不知道为什么。
System.Runtime.InteropServices.COMException
请协助。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.Storage.AccessCache;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace App1
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
doPickFile();
//Application.Current.Exit();
}
private async void doPickFile()
{
bool folderAdded = StorageApplicationPermissions.FutureAccessList.ContainsItem("\\\\server\\share$");
if (!folderAdded)
{
var openPicker = new FolderPicker() { SuggestedStartLocation = PickerLocationId.PicturesLibrary };
StorageFolder folder = await openPicker.PickSingleFolderAsync();
if (folder.Path == "\\\\server\\share$")
{
StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder);
}
}
else
{
StorageFolder pickedFolder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync("\\\\server\\share$");
await Windows.System.Launcher.LaunchFolderAsync(pickedFolder);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
具体地说,调试器在以下行停止:
StorageFolder folder = await openPicker.PickSingleFolderAsync();
您必须添加一个FileTypeFilter。
var openPicker = new FolderPicker() { SuggestedStartLocation = PickerLocationId.PicturesLibrary };
openPicker.FileTypeFilter.Add("*");
StorageFolder folder = await openPicker.PickSingleFolderAsync();
Run Code Online (Sandbox Code Playgroud)
奇怪的是:您也可以使用FileTypeFilter.Add(".anytext")代替,FileTypeFilter.Add("*")因为Windows中的当前FolderPicker实际上并不筛选文件类型。因此,我无法解释为什么您必须这样做。
| 归档时间: |
|
| 查看次数: |
808 次 |
| 最近记录: |