Path.GetTempPath Path.GetTempPath Path.GetTempPath 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 backslash.

Exceptions

The caller does not have the required permissions.

Examples

The following code shows how to call the GetTempPath method.

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

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.

  2. The path specified by the TEMP environment variable.

  3. The path specified by the USERPROFILE environment variable.

  4. The Windows directory.

Security

EnvironmentPermission
for unrestricted access to environment variables. Associated enumeration: Unrestricted

Applies to