2016-11-07 5 views
3

폴더 (바로 가기처럼)를 열뿐 아니라 사용자 정의 색상과 큰 아이콘으로 새로운 시작 타일 디자인을 허용하는 범용 앱을 만들려고합니다.유니버설 앱 FolderPicker System.Runtime.InteropServices.COMException

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

는 특히 디버거는 줄에서 중지 : StorageFolder folder = await openPicker.PickSingleFolderAsync();

+0

비동기를 사용하지 않고 사용해 보셨습니까? 그렇지 않다면 먼저 비동기없이 시도하십시오! 대부분의 COM 예외는 스레드에 의해 던져지고 또는 당신은 적절한 방법으로 스레드를 사용하지 말 수 있습니다 –

+0

아직 솔루션이 없습니까? – VillasV

답변

3

저도 같은 문제와 FolderPicker의 행동을했다 나 (특히 예외), 매우 버그를 보이지만 여기에 해결 방법입니다 :

var openPicker = new FolderPicker() { SuggestedStartLocation = PickerLocationId.PicturesLibrary }; 
    openPicker.FileTypeFilter.Add(".sometext"); 
    StorageFolder folder = await openPicker.PickSingleFolderAsync(); 

FolderPicker에 FileTypeFilter를 추가하기 만하면됩니다.

FolderPicker는 실제로 파일 형식을 필터링하지 않으므로 추가하는 FileTypeFilter의 종류는 중요하지 않습니다.

+0

새로운 질문이있는 경우 [Ask Question] (/ questions/ask) 버튼을 클릭하여 질문하십시오. 이 컨텍스트를 제공하는 데 도움이되는 경우이 질문에 대한 링크를 포함하십시오. –

+0

죄송하지만이 사실을 명확히하지는 못했지만 실제로는 질문에 대한 답변입니다. – Simon

+0

그에 따라 내 대답을 편집했습니다. – Simon