Path.GetTempPath Method

Definition

Returns the path of the current user's temporary folder.

public:
 static System::String ^ GetTempPath();
public static string GetTempPath ();
static member GetTempPath : unit -> string
Public Shared Function GetTempPath () As String

Returns

The path to the temporary folder, ending with a DirectorySeparatorChar.

Exceptions

The caller does not have the required permissions.

Examples

The following code shows how to call the GetTempPath method.

Dim result As String = Path.GetTempPath()
Console.WriteLine(result)
string result = Path.GetTempPath();
Console.WriteLine(result);

This example produces output similar to the following.

C:\Users\UserName\AppData\Local\Temp\

Remarks

The method does not verify that the path exists or test to see if the current process can access the path.

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

  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.

In .NET 7 and later, when the process calling the method is running as SYSTEM, the method skips the preceding sequence and returns C:\Windows\SystemTemp. This location is inaccessible to processes not running as SYSTEM.

Applies to

See also