将文件写入 Hololens Documents 目录的问题。目录未找到异常

Issues writing files to Hololens Documents directory. DirectoryNotFoundExcpetion

使用 HoloLens2 模拟器时,我能够成功地将我的 .csv 文件生成到我的桌面路径(例如 C:\Users\name\Desktop);但是,当我使用路径时出现 DirectoryNotFoundException 错误(如 Windows 设备门户文件资源管理器中显示的那样)U:\Users\name\Documents.

错误:

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

代码:

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);
            }
        }
    }

如有任何帮助,我们将不胜感激!

Windows 设备门户中显示的路径无法直接访问。据我所知,它们是内部的。

您可以改用 Application.persistentDataPath 来存储数据。
然后它将保存到“User Folders\LocalAppData\ProjectName\LocalState\..”,如 Windows 设备门户中所示。