Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Path.GetTempPath() always returns %USERPROFILE%

I've written a program that calls the System.IO.Path.GetTempPath() function. All the documentation I've read (like this one) says that the function should return the first path found from this list:

  • The path specified by the TMP environment variable.
  • The path specified by the TEMP environment variable.
  • The path specified by the USERPROFILE environment variable.
  • The Windows directory.

I have defined both the TMP and TEMP environment variables to be %USERPROFILE%\AppData\Local\Temp, but the call to GetTempPath() always returns my %USERPROFILE% directory instead of the values I've define for TMP and TEMP. How can I get the function to return the temporary directory I've defined?

like image 260
Gillfish Avatar asked Jun 16 '26 16:06

Gillfish


1 Answers

That is an Environment setting. http://msdn.microsoft.com/en-us/library/77zkk0b6.aspx

var tmp = Environment.GetEnvironmentVariable("tmp");

UPDATE: I went to a command prompt and did

SET TMP=C:\Temp

Then I launched visual studio from my command prompt. Now my environment is updated and visual studio sees it. The code above (as well as yours) worked for me. It displayed the updated environment settings.

So I believe you would have to kill explorer or logoff in order to get the new environment to be seen permenantly.

like image 113
phillip Avatar answered Jun 19 '26 06:06

phillip