2012/02/25

C# 取得 windows 下TEMP目錄


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 ;-) )

出處

沒有留言: