Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the path returned by Path.GetTempPath() stay constant?

Tags:

c#

.net

temp

I have a Web Service that calls another Executable which fetches a list of files and stores them at a temporary location, which will in turn be read by the web service.

I thought i will use the system's temp folder and found out that i could use System.IO.Path.GetTempPath function to get the temp folder and store my files here. But when i checked the output returned by this function it gave me

C:\Users\username\AppData\Local\Temp\15\

i am worried about the \15 at the end of the path. Does this mean that the temp folder returned by GetTempPath is not constant and keeps changing? I need it to be constant since i need the web service to read from the temp files output by the executable

like image 516
Sadhir Avatar asked Jun 26 '12 16:06

Sadhir


2 Answers

The documentation says:

This method checks for the existence of environment variables in the following order and uses the first path found:

1.The path specified by the TMP environment variable.

  1. The path specified by the TEMP environment variable.

  2. The path specified by the USERPROFILE environment variable.

  3. The Windows directory.

So unless you change your environment the result is stable.

(Environment changes can occur, if you run as a service account, which never did an interactive logon), which has a default %SystemRoot%\Temp folder. If someone logs on to the server with this service account, a profile is created and the temp path will change)

like image 113
Joey Avatar answered Sep 21 '22 15:09

Joey


Even if this post is somewhat older, I would like to share knowledge :-)

When running on a Terminalserver it is the default behavior of Windows to create a separate temporary subfolder for every connection to this server. There are ways to affect this but before you want to do this I would recommend to place your files somewhere else.

(http://blogs.msdn.com/b/oldnewthing/archive/2011/01/25/10119675.aspx)

like image 40
AlexS Avatar answered Sep 19 '22 15:09

AlexS