현재 Logfile을로드하고 DevExpress XtraGrid에 표시하기 위해 처리하는 샘플 Windows 8 App을 개발 중입니다. 내가 파일 유형 필터에 필요한 확장을 추가 할 때, 코드는 내가 appxmanifest에 파일 확장자를 추가 되었더라도 UnauthorizedAccessException 예외 :FileOpenPicker가 UnauthorizedAccessException을 throw합니다.
private void OpenFile()
{
try
{
FileOpenPicker pickLog = new FileOpenPicker();
pickLog.CommitButtonText = "Logdatei öffnen";
pickLog.SuggestedStartLocation = PickerLocationId.ComputerFolder;
pickLog.ViewMode = PickerViewMode.List;
pickLog.FileTypeFilter.Add(".log"); //This is where the code jumps out
pickLog.FileTypeFilter.Add(".slg");
pickLog.PickSingleFileAsync().Completed += delegate
{
StorageFile logFile = pickLog.PickSingleFileAsync().GetResults();
Stream strLog = logFile.OpenStreamForReadAsync().Result;
vm.LoadCommand.Execute(strLog);
};
pickLog.PickSingleFileAsync();
}
catch (Exception ex) //Catches UnauthorizedAccessException
{
MessageDialog md = new MessageDialog(ex.Message, ex.GetType().ToString());
md.ShowAsync();
}
}
더 나쁜 것은이있다 내가 FileTypeFilter 라인을 주석 경우, 코드가 내가 거기에 추가 익명 메소드 밖으로 점프 :
private void OpenFile()
{
try
{
FileOpenPicker pickLog = new FileOpenPicker();
pickLog.CommitButtonText = "Logdatei öffnen";
pickLog.SuggestedStartLocation = PickerLocationId.ComputerFolder;
pickLog.ViewMode = PickerViewMode.List;
//pickLog.FileTypeFilter.Add(".log");
//pickLog.FileTypeFilter.Add(".slg");
pickLog.PickSingleFileAsync().Completed += delegate //This is where the code jumps out
{
StorageFile logFile = pickLog.PickSingleFileAsync().GetResults();
Stream strLog = logFile.OpenStreamForReadAsync().Result;
vm.LoadCommand.Execute(strLog);
};
pickLog.PickSingleFileAsync();
}
catch (Exception ex) //Catches COMException
{
MessageDialog md = new MessageDialog(ex.Message, ex.GetType().ToString());
md.ShowAsync();
}
}
내가 바로 여기에 문제를 제기하는 이유입니다 결과 (StackOverflow에 포함 소스), 작업없이 끝에 일에 대한 철저한 연구를했다. , COMException이 throw되었습니다
의 HRESULT는 항상 (0x80070005입니다)하지만, 내부 HRESULT (세부 정보 창에 표시되는 HRESULT)은 일반적으로 -21474xxxx했다 : 나는
가 UPDATE
"코드가 튀어 나옴"이란 무엇을 의미합니까? –
ComputerFolder가 아닌 다른 SuggestedStartLocation을 시도 했습니까? – Uwe
@BenRobinson "코드가 튀어 나옵니다"라는 말은 코드가 더 이상 실행되지 않고 catch 블록에 직접 연결된다는 의미입니다. – AlphaNERD