Alex Rivera | Logout

Correct location to save a temporary file in Windows?

Asked 2009-04-15T16:09:35.767
47

I have a file I need to write to a temp location, what is the best place in Windows? This file needs to not move as I need to read it a couple of times and dispose it when I close the program.

Edit
Report

1 Answer

43

use

Path.GetTempPath();

or

Path.GetTempFileName();

As commentator pointed out, GetTempFileName() is not threadsafe - but you can construct unique file names based on GUIDs.

answered 2009-04-15T16:13:28.923

Your Answer