Find the temporary folder

  • Thread starter Thread starter =?iso-8859-1?Q?Asbj=F8rn_Ulsberg?=
  • Start date Start date
?

=?iso-8859-1?Q?Asbj=F8rn_Ulsberg?=

I just wonder if it's a simpler way to get the path to the current user's
temporary folder than this:

string path = Path.GetFullPath(Path.Combine(Environment.GetFolderPath(
Environment.SpecialFolder.LocalApplicationData), "..\\Temp"));

It works, but is quite cumbersome. I also find it strange that
Path.Combine()
doesn't fix the '..\' part, so I need to use Path.GetFullPath() to have the
'..\' resolved (it walks down one directory from the '..\Local Settings\
Application Data' folder and gives '..\Local Settings').
 
Asbjørn Ulsberg said:
I just wonder if it's a simpler way to get the path to the current user's
temporary folder than this:

string path = Path.GetFullPath(Path.Combine(Environment.GetFolderPath(
Environment.SpecialFolder.LocalApplicationData), "..\\Temp"));

It works, but is quite cumbersome. I also find it strange that
Path.Combine()
doesn't fix the '..\' part, so I need to use Path.GetFullPath() to have the
'..\' resolved (it walks down one directory from the '..\Local Settings\
Application Data' folder and gives '..\Local Settings').

Usually %temp% points to the temp folder, so you could try
'Environment.GetEnvironmentVariable("temp")'.

Niki
 
Asbjørn Ulsberg said:
I just wonder if it's a simpler way to get the path to the current user's
temporary folder than this:

string path = Path.GetFullPath(Path.Combine(Environment.GetFolderPath(
Environment.SpecialFolder.LocalApplicationData), "..\\Temp"));

How about

string path = System.Environment.GetEnvironmentVariable("TEMP");
 
Asbjørn Ulsberg said:
I just wonder if it's a simpler way to get the path to the current user's
temporary folder than this:

string path = Path.GetFullPath(Path.Combine(Environment.GetFolderPath(
Environment.SpecialFolder.LocalApplicationData), "..\\Temp"));

It works, but is quite cumbersome. I also find it strange that
Path.Combine()
doesn't fix the '..\' part, so I need to use Path.GetFullPath() to have the
'..\' resolved (it walks down one directory from the '..\Local Settings\
Application Data' folder and gives '..\Local Settings').

System.IO.Path.GetTempPath();


Arild
 
Hi,
I just wonder if it's a simpler way to get the path to the current user's
temporary folder than this:

string path = Path.GetFullPath(Path.Combine(Environment.GetFolderPath(
Environment.SpecialFolder.LocalApplicationData), "..\\Temp"));

It works, but is quite cumbersome. I also find it strange that
Path.Combine()
doesn't fix the '..\' part, so I need to use Path.GetFullPath() to have the
'..\' resolved (it walks down one directory from the '..\Local Settings\
Application Data' folder and gives '..\Local Settings').

Use:

Path.GetTempPath()

Other way is to get path from environmental variable by:

Environment.GetEnvironmentVariable("TEMP")
or
Environment.GetEnvironmentVariable("TMP")

Regards

Marcin
 
Usually %temp% points to the temp folder, so you could try
'Environment.GetEnvironmentVariable("temp")'.

Ah, of course. The only difference is that %temp% returns the short
version of the folder names, e.g. 'C:\DOCUME~1' instead of
'C:\Documents and Settings'.
 
Back
Top