- Home /
How to read a file from OneDrive folder in HoloLens app
Hi,
In my HoloLens application, I'm trying to read the files located in the OneDrive folder. The OneDrive app is installed on the device.
I would like to pick the file when my app boots for the first time, and save the path to retrieve it automatically in the future.
The issue is that after picking the file and saving its path, I can't find it again.
In the following snippet of code, File.Exists always returns false when I build the project with IL2Cpp. It works fine with .NET when I add the "broadFileSystemAccess" capability.
I'm using Unity 2018.2.0f2. Is there any reason why this code would work with .NET but not with IL2Cpp, even with the same capabilities?
private async void OpenFileAsync()
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
openPicker.FileTypeFilter.Add(".txt");
StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
// Application now has read/write access to the file
UnityEngine.WSA.Application.InvokeOnAppThread(()=> ShowFileStatus(file.Path), false);
}
else
{
Debug.Log("No file picked");
}
}
private void ShowFileStatus(string filepath)
{
Debug.Log($"File {filepath} exists: {File.Exists(filepath)}");
}
I would recommend submitting a bug report. I don't believe that we have tried IL2CPP with Hololens and the OneDrive app, so something might not be implemented correctly.