Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct location to save a temporary file in Windows?

Tags:

c#

windows

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.

like image 598
Scott Avatar asked Apr 15 '09 16:04

Scott


People also ask

Where do I put temporary files?

Temp files often have the extension . TMP and are stored in the C:\Users\AppData\Local\Temp folder. If you're working on a document, your word-processing app may create a temporary file to track your progress. If the app crashes, you'll be able to recover your data from the temp file.

Which folder does Windows use to store temporary files?

C:\WINDOWS\TEMP This directory stores temporary files generated by Windows itself. Most of what's stored here can be deleted as long as it's not locked for use. These two related directories are the other most crucial temporary data folders in the system.

Where does temporary files get stored in Windows 10?

C:\Users\<Username>\AppData\Local\Temp (This folder contain temporary information while a process is creating other files).

What is the Temp folder in Windows?

The Temp folder is a directory on your Windows PC used to store temporary files. Clearing the Temp folder is a standard procedure for system administration to reduce the amount of storage space used.


1 Answers

use

Path.GetTempPath(); 

or

Path.GetTempFileName(); 

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

like image 124
tanascius Avatar answered Sep 24 '22 08:09

tanascius