Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.

Save file on Hololens not in local app folder

What im trying to do is exporting my Worldanchors to a byte file with the WorldAnchorTransferBatch class of Unity. I dont know however how to save this file in a folder "globally" so if i uninstall my app its still there. I guess the best place to save the file is the DocumentsLibrary but microsoft states that the Documents library is not intended for general use. And how would i even save a file to it?

Someone has any idea how to do this?

Best Answer

  • ReeleyReeley ✭✭✭
    edited May 2017 Answer ✓

    Ok so i fiddled around and this is my solution:

    #if WINDOWS_UWP
        static async void SaveData(byte[] data)
        {
            Windows.Storage.StorageFolder storageFolder = Windows.Storage.KnownFolders.CameraRoll;
            Windows.Storage.StorageFile sampleFile = await storageFolder.CreateFileAsync("anchors.dat", Windows.Storage.CreationCollisionOption.ReplaceExisting);
        }
    #endif
    

    you also have to wrap your method call into an #if#endif and you have to enable access to the CameraRoll folder by enabling picturelibrary in your appmanifest in your VS solution or you can enable the picturelibrary in unity in your capability settings

    Its kind of stupid that i only can save my data to music, videos or pictures although its not such file :/ but hey it works

Answers

  • You will need to use a FileOpenPicker, since apps on HoloLens have to be universal windows platform (uwp) with file-related security restrictions. See .Net StorageFile class and FileOpenPicker.

  • ReeleyReeley ✭✭✭
    edited May 2017

    Ok i tried what you said but i cant get this to work can you give me a code example if i wanted to save the following byte array to lets say the document library?

    static void SaveData(byte[] data)
        {
    
        }
    

    I tried this:

        static void SaveData(byte[] data)
                {
    #if !UNITY_EDITOR && UNITY_METRO
                    Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
                    Windows.Storage.StorageFile sampleFile = await storageFolder.CreateFileAsync("sample.txt", Windows.Storage.CreationCollisionOption.ReplaceExisting);
    #endif
                }
    

    i cant even compile this cause i cant add the async to my function because async is not available in C# 4 and then i cant use await.

  • ReeleyReeley ✭✭✭
    edited May 2017 Answer ✓

    Ok so i fiddled around and this is my solution:

    #if WINDOWS_UWP
        static async void SaveData(byte[] data)
        {
            Windows.Storage.StorageFolder storageFolder = Windows.Storage.KnownFolders.CameraRoll;
            Windows.Storage.StorageFile sampleFile = await storageFolder.CreateFileAsync("anchors.dat", Windows.Storage.CreationCollisionOption.ReplaceExisting);
        }
    #endif
    

    you also have to wrap your method call into an #if#endif and you have to enable access to the CameraRoll folder by enabling picturelibrary in your appmanifest in your VS solution or you can enable the picturelibrary in unity in your capability settings

    Its kind of stupid that i only can save my data to music, videos or pictures although its not such file :/ but hey it works

  • Sorry been distracted advertising. You are on the right track. Will spend some time on post with more info later.

    Also consider ApplicationData class for roaming. It is in kind of a hidden folder just for your app (walled garden) but can follow you for your app when you roam across devices. See https://docs.microsoft.com/en-us/uwp/api/windows.storage.applicationdata

    I do think most people will want to use a FileOpenPicker to go anywhere on their drive. It is also async and trickier and has to be in a WSA,Application thread, see https://docs.unity3d.com/ScriptReference/WSA.Application.InvokeOnUIThread.html

  • ReeleyReeley ✭✭✭

    hmm LocalCacheFolder/RoamingFolder sound promissing, but arent my files deleted there when i reinstall my app?

    I dont need the FileOpenPicker the path will be hardcoded as it is right now.

Sign In or Register to comment.