How to save files in a specific path in Hololens2?

FrogsHunter 16 Reputation points
2022-08-01T04:05:06.753+00:00

I'm a beginner in this area. I'm trying to record videos and eye gaze data by Hololens2. Now I have written a little unity3D project to achieve this. I successfully record the data by using function:"string filepath_in_function2 = Application.persistentDataPath + "/position_Cursor_IO.csv";". But they are only accessed by Windows Device Portal. I have two hololens. One of them has some issues with Windows Device Portal. It takes a very long time to load the files, and I can't download them. I was wondering is there any other way to save data in the Hololens2 that can be accessed easily?226568-4.jpg226631-5.jpg

HoloLens | Development
{count} votes

1 answer

Sort by: Most helpful
  1. Jay Zuo - MSFT 171 Reputation points Microsoft Employee Moderator
    2022-08-02T03:44:24.17+00:00

    Hello @FrogsHunter , Welcome to Microsoft Q&A,

    Please note that HoloLens App is also a UWP app and UWP apps can only access certain file system locations by default. Your app does not have access to most of the file system. For more details, please see File access permissions.

    It's recommended to let the user select the folder location by using a file picker. For more info, see Open files and folders with a picker. When your app retrieves the folder via picker, you can add it to the FutureAccessList so that your app can readily access that item in the future.

    void SelectFolder()  
    {  
    #if ENABLE_WINMD_SUPPORT  
        UnityEngine.WSA.Application.InvokeOnUIThread(async () =>  
        {  
            var folderPicker = new Windows.Storage.Pickers.FolderPicker();  
            folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;  
            folderPicker.FileTypeFilter.Add("*");  
      
            Windows.Storage.StorageFolder folder = await folderPicker.PickSingleFolderAsync();  
            if (folder != null)  
            {  
                // Application now has read/write access to all contents in the picked folder  
                // (including other sub-folder contents)  
                Windows.Storage.AccessCache.StorageApplicationPermissions.  
                FutureAccessList.AddOrReplace("PickedFolderToken", folder);  
            }  
        }, false);  
    #endif  
    }  
    

    Then you can create file and write to it as per Create, write, and read a file.

    async void SaveFile()  
    {  
    #if ENABLE_WINMD_SUPPORT  
        if (Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.ContainsItem("PickedFolderToken"))   
        {  
            Windows.Storage.StorageFolder storageFolder = await Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.GetFolderAsync("PickedFolderToken");  
            Windows.Storage.StorageFile sampleFile = await storageFolder.CreateFileAsync("sample.txt", Windows.Storage.CreationCollisionOption.OpenIfExists);  
            await Windows.Storage.FileIO.WriteTextAsync(sampleFile, "Swift as a shadow");  
        }  
    #endif  
    }  
    

    ----
    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.