Question

I am creating an installable extension for ArcMap using C#/WPF/VS2010. (which may or may not have any bearing here). One thing I would like to do is store data in the users temporary folder. So, I get the folder like so:

public static string SystemTempPath = Path.GetTempPath();

When I compile everything and Bind to the variable (indirectly) in the WPF designer I got this in the preview pane:

"C:\Users\<username>\AppData\Local\Temp\"

Great, thats what I am after. But when I run the extension in ArcMap I get something like the following:

"C:\Users\<username>\AppData\Local\Temp\arcA6C5\"

Note the extra folder at the end which changes every time I reload ArcMap. So it seems that since this is an extension and I am somewhat at the mercy of the ArcMap kernel, it is using ArcMap's created temp folder and not the user temp var.

My question: Is there a way to get around this grammatically other then a string manipulation? I could assume that this extra will always be there and simply truncate but this way seems somewhat dirty. I have tried this as well with the same result:

System.Environment.GetEnvironmentVariable("TEMP");
System.Environment.GetEnvironmentVariable("TMP");

Which would only be slightly less dirty anyway.

Thanks for any help.

Was it helpful?

Solution

The problem is that ArcMap is changing it's runtime environment (the TEMP and TMP environment variables) to create a unique temp folder for each run. Any Windows API call to retrieve the temp folder will return the updated ones (by design).

One thing I would like to do is store data in the users temporary folder.

I would recommend storing the data within the user's application data folder instead. This is an appropriate place to store user data, and will be consistent. Try something like:

var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
path = Path.Combine(path, @"YourCompany\YourProduct\");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top