Search code examples
c#uwponedrivehololensfileopenpicker

Can't access file on OneDrive; HoloLens runtime


I started working with the Microsoft HoloLens.

I am completely new to C# programming. So this could be a simple or even stupid question, but I just can't explain it and couldn't find any information about it. I work with Unity 2018.4.21f1 Visual Studio 2019 and the already mentioned HoloLens.

Desired behaviour:

I would like to program an app that opens a FileExplorer where I can select OneDrive from the drop down menu, choose a .obj-file (let's take cube.obj as an example) and this file gets processed and rendered at runtime.

Current behaviour:

I can use a FileOpenPicker to select a file from OneDrive, but then the following error message appears:

Exception thrown at 0x76C330D2 in APP.exe: Microsoft C++ exception: Il2CppExceptionWrapper at memory location 0x0210C090. DirectoryNotFoundException: Could not find a part of the path "C:\Data\Users\marcu\AppData\Local\Packages\microsoft.microsoftskydrive_8wekyb3d8bbwe\LocalState\OpenFile\cube.obj".

Notes:

  • Everything works perfectly fine if cube.obj is stored locally on the HoloLens. So it could be related to the cloud based storage, but I can print the path, though.
  • Works with Unity Editor too.
  • The path is not longer than 260 signs.
  • There are no spaces in the path.
  • Maybe I just lack the appropriate search syntax to find the answer.
  • Unfortunately, searching the error code was not helpful.
  • I can also add a code snippet, but in principle it is very similar to the first example from here. The only difference is that I store the path with file.Path in a string.

If someone had a similar problem and could help me to solve this one or could give me a hint, I would be very grateful.


Solution

  • UWP apps can only access certain file system locations by default such as ApplicationData and Package.InstalledLocation. Unfortunately, you cannot directly access the files in OneDrive through the path.

    But you can copy this file from OneDrive to ApplicationData.Current.LocalFolder by calling the method StorageFile.CopyAsync(). Because the LocalFolder is the folder where your app can store data freely and be created when your app is installed, you can access this file from LocalFolder by the string path.