0

My file, located at 'C:/Users/Username/Desktop/sample.pdf' is there. I can open it manually and it loads fine. Now if I put an invalid link, such as, file:///sample.pdf, which clearly can't be found, the Hololens app will open the Edge browser attempting to open the pdf. So, it's clear the code is functioning.

So why then is this uri incorrect when loading in the Hololens at run-time?

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

Here is the exception thrown.

Exception thrown: 'System.ArgumentException' in Assembly-CSharp.dll

WinRT information: The provided URI scheme can't be launched. Unhandled 'Platform.InvalidArgumentException' exception caught! - 'The parameter is incorrect.'

The parameter is incorrect. The provided URI scheme can't be launched.', Sender: 'null'. Missing try/catch blocks.

The tricky thing with these exceptions in the Hololens is sometimes they don't seem to be related to whats not working. I've tried googling the error and nothing helpful appears.

EDIT: string uriToLaunch = @"file:///Data/myFiles/sample.pdf"; returns WinRT information: The provided URI scheme can't be launched. The parameter is incorrect.

string uriToLaunch = @"/Data/myFiles/sample.pdf"; returns UriFormatException: Invalid URI: The format of the URI could not be determined.

NOTE I thought I could open the Edge browser from the app but I'm having trouble replicating this functionality. The only thing that responds, positively, shall we say, is

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

This opens up a separate dialog box that will take my to the MS store to try and buy an app that will open ms-appx files.

EDIT 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();

I've tried implementing this simple FileOpenPicker, just to test and see if I could get one working, to no success.

It throws this:

Exception thrown: 'System.Exception' in mscorlib.ni.dll

Unhandled 'Platform.COMException' exception caught! - 'Invalid window handle.

EDIT 3: This is all I can find on the error.

COMException If the ErrorCode property of the exception has the value 0x80070578 (ERROR_INVALID_WINDOW_HANDLE), this indicates that the method was not called on the UI thread.

EDIT 4: Now it's crashing and returning:

Exception thrown: 'System.Exception' in mscorlib.ni.dll

The program '[4084] hololensapplication.exe' has exited with code -1073741189 (0xc000027b).

jtth
  • 876
  • 1
  • 12
  • 40
  • When you say "at run time" what kind of application is this ? WinForms, Browser, Console ? – PhillipH Jun 29 '17 at 15:19
  • Any reason you add the "file:///" ? Uri handles passing it without it just fine. For example: https://stackoverflow.com/questions/1546419/convert-file-path-to-a-file-uri – Rand Random Jun 29 '17 at 15:23
  • Sounds like you might want to use a relative path to link to your document. If the applications does not have access to your C:/ directory then it does not know where to look for the file. This looks like a problem with an ASP.NET application since a .dll file is mentioned. Try putting your file in your project folder and link to it there. – Kanstantsin Arlouski Jun 29 '17 at 15:23
  • Just for some clarity, when you say that you can open the file manually, do you mean on a PC or the HoloLens? @JHiggins – James Croft Jun 29 '17 at 15:47
  • 1
    UWP Apps are sandboxed. So you will not be able to open any File that is outside the scope of App. You need to use FileExplorer and get the file so that you can open the file. – AVK Jun 29 '17 at 16:23
  • @AVK Understood. Though the file I'm trying to access is within the Apps folder. I know I can access files within the apps folder as I'm doing other things with model files (.stl) and picture files (.jpg, etc) and these work fine within the app. Edit: To be clear when I say local, /Data/myFiles/, is the path from which I'm manipulating these other file types through. Though I am not using Uri methods to access these. I'm not familiar with URI or FileExplorers. Any links or advice is greatly appreciated – jtth Jun 29 '17 at 17:06
  • [Here](https://learn.microsoft.com/en-us/uwp/api/Windows.Storage.Pickers.FileOpenPicker) is a link for `FileOpenPicker` that will help you open a file which is outside the scope of Application. – AVK Jun 29 '17 at 17:58

1 Answers1

0

As @AVK points out, UWP apps are sandboxed. This means files outside of the Hololens local environment aren't reachable. There are local known folders on the HoloLens, but the only way to get around this is to use third party apps such as OneDrive, Azure, etc.

jtth
  • 876
  • 1
  • 12
  • 40