Sep 27, 2011

Getting the temp folder in c#


Another reminder to myself : 


To get the temp path in c#, the most used option I have seen is :


string tempPath = Environment.GetEnvironmentVariable("Temp");


which works ok most of the time, but personally I don't like to pass string variables around, 
so I went looking for something as : 
string tempPath = Environment.GetFolderPath(SpecialFolder.Temp);
which ofcourse does not exist. 


But as with google as a friend, I found the best way (for me) : 


String tempPath = Path.GetTempPath();


(always in the last place you look of course ;-) )

No comments:

Post a Comment