Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a path suitable for storing temporary files?

Tags:

c#

.net

C# 2008 SP1

I have created an updater for our clients application. The way the updater works is to download all the updated files and store them in a temporary folder then check the file hashes. If everything is ok it will copy the files to the applications installation folder. Once this is been completed it will delete all the updated files in the temporary directory.

My problem: I am looking for a directory that will be available for XP, Vista, and Win7. I was thinking about the 'temp' directory. However, when I do this:

Environment.SpecialFolder.

There is no enum for temp directory. What would be the next best thing to store these temporary files?

Many thanks for any advice,

like image 973
ant2009 Avatar asked Aug 18 '09 11:08

ant2009


Video Answer


2 Answers

From How to get Temporary Folder using .NET (C#):

string sPath;
sPath = Path.GetTempPath();    
Console.WriteLine("Temporary Path := " + sPath );
like image 161
Giovanni Galbo Avatar answered Sep 20 '22 15:09

Giovanni Galbo


You can use either Path.GetTempPath() or Path.GetTempFileName() (if you don't need to have control over the file name)

like image 42
Fredrik Mörk Avatar answered Sep 21 '22 15:09

Fredrik Mörk