1

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.

Ernie S
  • 13,902
  • 4
  • 52
  • 79

1 Answers1

0

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\");
Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • Thanks Reed. Thats what I figured. I was liking the idea of using the Temp folder so it can be cleanup with all the other user temp files (if and when then happens). I already have a app data folder for storing settings but if I use then then I have to worry about it cleaning it up. Have to think about it some more. – Ernie S Jul 01 '13 at 11:36