Most of the applications consuming my add-in return "C:\Users\[username]\AppData\Local\Temp\" path. But one application is returning "C:\Users\[username]\AppData\Local\Temp\1affa5dd-2f26-4c96-9965-7a78f5c76321\". The GUID in the end changes every time I launch the application.
The application that I am running my add-in from are Revit 2015-2020. Revit versions 2015-2019 return the correct path. But Revit 2020 is returning the path with GUID appended in the end. The code remains the same.
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;
}
I am expecting the path, "C:\Users\[username]\AppData\Local\Temp\"
While I am actually getting path, "C:\Users\[username]\AppData\Local\Temp\1affa5dd-2f26-4c96-9965-7a78f5c76321\"
As per this forum link, Revit 2020
alters the value returned as per what you are seeing.
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.
I made an small fix wich splits the Path by the '\' character and composes a string until the word 'Temp', it works but consider it a concept.
private void concept()
{
string fullpath = Path.GetTempPath();
string[] ph = fullpath.Split('\\');
bool fix = false;
string fixedpath = "";
foreach (string word in ph)
{
if (fix == false)
{
fixedpath = fixedpath + word + @"\";
}
if (word.ToLower().Equals("temp"))
{
fix = true;
}
}
MessageBox.Show(fixedpath);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With