c# - 使用 Revit 2020 时,Path.GetTempPath() 方法最后返回带有 GUID 的 UserTempPath

标签 c# .net revit .net-4.7.2

大多数使用我的加载项的应用程序返回“C:\Users\[用户名]\AppData\Local\Temp\”路径。但是一个应用程序返回“C:\Users\[用户名]\AppData\Local\Temp\1affa5dd-2f26-4c96-9965-7a78f5c76321\”。每次我启动应用程序时,最后的 GUID 都会改变。

我运行加载项的应用程序是 Revit 2015-2020。 Revit 版本 2015-2019 返回正确的路径。但是 Revit 2020 返回的路径最后附加了 GUID。代码保持不变。

    public static string GetLocalFilePath(string sourceUri, string fileName, string extension)
    {
        string[] sasTokenSeparated = sourceUri.Split('?');
        string[] uriParts = sasTokenSeparated[0].Split('/');
        string documentId = uriParts[uriParts.Length - 2];
        documentId = documentId.Split('.')[0];
        string extensionWithDot = string.Empty;
        if (!extension.StartsWith("."))
        {
            extensionWithDot = "." + extension;
        }
        else
        {
            extensionWithDot = extension;
        }
        string localPath = Path.Combine(Path.GetTempPath(), documentId, fileName + fileExtension);
        return localPath;
    }

我期待的路径, “C:\Users\[用户名]\AppData\Local\Temp\”

虽然我实际上正在寻找路径, “C:\Users\[用户名]\AppData\Local\Temp\1affa5dd-2f26-4c96-9965-7a78f5c76321\”

最佳答案

根据 this forum link , Revit 2020 根据您所看到的改变返回的值。

Since Revit 2020 the requested temp path contains an additional guid at the end of the path, which changes after every restart of Revit(ie. C:\Users\USERNAME\AppData\Local\Temp\84ae8c0d-197b-4b44-b8d3-8823fabbba4f). It seems like Revit changes the temp path for the scope of the application.

关于c# - 使用 Revit 2020 时,Path.GetTempPath() 方法最后返回带有 GUID 的 UserTempPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56984043/

相关文章:

c# - 在 TextBox 上使用 StringFormat 绑定(bind)到 double

c# - 转换所有参数、返回类型、类定义以使用接口(interface)

c# - IValueConverter 和可见性

c# - Revit API : How to create Element Keynote for a wall and Material Keynote?

c# - MVC 4 强类型 View 不传递 Controller 模型

c# - .Net Standard 2.0 dll 的 .Net 45 序列化

asp.net - 遍历结果集.Net

c# - 如何更改文本框的背景颜色?

c# - 同步或重新加载后更改的 Revit API 2013 文档看不到新添加或更改的元素

c# - Revit API - 错误的完整类名