Search code examples
c#hololensmrtkwindows-mixed-reality

Issues writing files to Hololens Documents directory. DirectoryNotFoundExcpetion


When using the HoloLens2 emulator, I am able to successfully generate my .csv files to my desktop path (e.g. C:\Users\name\Desktop); however, I get a DirectoryNotFoundException error when I use the path (as displayed on the Windows Device Portal File Explorer) U:\Users\name\Documents.

Error:

DirectoryNotFoundException: Could not find a part of the path "U:\Users\name\Documents\rWrist.csv". at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x00000] in <00000000000000000000000000000000>:0

Code:

string basePath = @"U:\Users\name\Documents\";

    foreach (var getSave in getDictionary)
    {
        string saveLocation = $"{basePath}{getSave.Key}.csv";
        File.WriteAllText(saveLocation, null);

        using (StreamWriter sw = new StreamWriter(saveLocation))
        {
            sw.WriteLine("{0},{1},{2},{3}", "Time", "xPos", "yPos", "zPos");

            foreach (var kvp in getSave.Value)
            {
                sw.WriteLine("{0},{1},{2},{3}", kvp.Key, kvp.Value.x, kvp.Value.y, kvp.Value.z);
            }
        }
    }

Any help would be much appreciated!


Solution

  • The path which appears on Windows Device Portal is not directly accessible as they are. As far as I know, they are internal.

    You can instead use Application.persistentDataPath to store data.
    It will then be saved to "User Folders\LocalAppData\ProjectName\LocalState\ .." as seen from Windows Device Portal.