Tomas
Tomas

Reputation: 18117

Path.GetTempPath() unexpected symbol at the end of path

I am trying to read Windows 2008 SP2 temp path using the code Path.GetTempPath(); and get unexpected result.

Instead of

C:\Users\Administrator\AppData\Local\Temp\

I get

C:\Users\Administrator\AppData\Local\Temp\2\

Why I get "2" at the end of path? There is no such temp path on my machine.

Upvotes: 0

Views: 632

Answers (2)

Jason Evans
Jason Evans

Reputation: 29186

Path.GetTempPath() looks for the Temp folder using

  1. The path specified by the TMP environment variable.
  2. The path specified by the TEMP environment variable.
  3. The path specified by the USERPROFILE environment variable.
  4. The Windows directory.

You might want to check the environment variables to see if any of those have a "2" at the end by mistake.

Upvotes: 0

Richard
Richard

Reputation: 109100

I've seen this when remotely connecting to a server that supports multiple sessions: each remote session, even for the same user, gets its own temp path.

I assume this is to prevent temporary files from two sessions by the same user possibly interfering.

I understand that setting "Use Temporary folders per session" in Terminal services configuration controls this behaviour.

Upvotes: 4

Related Questions