2017-06-29 73 views
0

我的文件位于'C:/Users/Username/Desktop/sample.pdf'。我可以手动打开它,并加载正常。现在,如果我放置了一个无效的链接,如file:///sample.pdf,显然无法找到,Hololens应用程序将打开试图打开PDF的Edge浏览器。所以,很明显代码正在运行。URI正确但在运行时不正确?

那么,为什么在运行时在Hololens中加载时这个uri不正确呢?

string uriToLaunch = "file:///C:/Users/Username/Desktop/sample.pdf"; 

    // Create a Uri object from a URI string 
    var uri = new Uri(uriToLaunch); 

    Task task = new Task(

     async() => 
     { 
      // Launch the URI 
      var success = await Windows.System.Launcher.LaunchUriAsync(uri); 

      if (success) 
      { 
       // URI launched 
      } 
      else 
      { 
       // URI launch failed 
      } 
     }); 

    task.Start(); 
    task.Wait(); 

这是抛出的异常。

抛出异常:在大会-CSharp.dll

WinRT的信息 'System.ArgumentException': 提供的URI方案无法启动。 未处理的“Platform.InvalidArgumentException”异常被捕获! - '参数不正确。'

该参数不正确。 提供的URI方案无法启动',发件人:'null'。缺少try/catch块。

Hololens中这些例外的棘手问题有时似乎与什么不起作用有关。我试着用Google搜索这个错误,并且没有任何有用的信息出现。

编辑:string uriToLaunch = @"file:///Data/myFiles/sample.pdf"; 返回WinRT信息:提供的URI方案无法启动。 该参数不正确。

string uriToLaunch = @"/Data/myFiles/sample.pdf"; 返回UriFormatException:无效URI:无法确定URI的格式。

注意我以为我可以从应用程序打开边缘浏览器,但我无法复制此功能。即响应,积极的,我们应该说的唯一的事情,是

@"ms-appx:///Data/myFiles/sample.pdf";

这将打开一个单独的对话框,将带我到MS商店尝试和购买的应用程序,将打开MS-APPX文件。

编辑2:

FileOpenPicker openPicker = new FileOpenPicker(); 
    openPicker.ViewMode = PickerViewMode.Thumbnail; 
    openPicker.ViewMode = PickerViewMode.Thumbnail; 
    openPicker.FileTypeFilter.Add(".jpg"); 
    openPicker.FileTypeFilter.Add(".jpeg"); 
    openPicker.FileTypeFilter.Add(".png"); 

    Task task = new Task(
    async() => 
    { 
     StorageFile file = await openPicker.PickSingleFileAsync(); 
     if (file != null) 
     { 
      // Application now has read/write access to the picked file 
      Debug.Log("Picked photo: " + file.Name); 
     } 
     else 
     { 
      Debug.Log("Cancelled"); 
     } 
    }); 

    task.Start(); 
    task.Wait(); 

我试图实现这种简单FileOpenPicker,只是为了测试,看看我能得到一个工作,没有成功。

它抛出这个:

抛出异常: 'System.Exception的' 在mscorlib.ni.dll

未处理 'Platform.COMException' 异常捕获! - '窗口句柄无效。

编辑3:这是我所能找到的错误。

COMException 如果异常的ErrorCode属性的值为0x80070578(ERROR_INVALID_WINDOW_HANDLE),则表明该方法未在UI线程上调用。

编辑4:现在,它的崩溃和恢复:

抛出异常: 'System.Exception的' 在mscorlib.ni.dll

程序 '[4084] hololensapplication.exe' 已与退出代码-1073741189(0xc000027b)。

+0

当你说“在运行时”这是什么样的应用程序? WinForms,浏览器,控制台? – PhillipH

+0

您添加“file:///”的任何原因? Uri处理通过它没有它就好了。例如:https://stackoverflow.com/questions/1546419/convert-file-path-to-a-file-uri –

+0

听起来像你可能想要使用相对路径链接到您的文档。如果应用程序无法访问您的C:/目录,则它不知道在哪里查找文件。这看起来像一个ASP.NET应用程序的问题,因为提到了一个.dll文件。尝试把你的文件放到你的项目文件夹中并链接到那里。 –

回答

0

正如@AVK指出的,UWP应用程序确实是沙盒。这意味着它们的本地环境以外的文件不可访问。 HoloLens上有本地已知的文件夹,但解决此问题的唯一方法是使用第三方应用程序,如OneDrive。抱歉,他们不是一个更简单的答案!