Skip to content

Update Path.GetTempPath description #10118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions xml/System.IO/Path.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2298,25 +2298,17 @@ On .NET 7 and earlier versions, when using this method on Windows, the <xref:Sys

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:

# [Windows](#tab/windows)

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.
If the current Windows version exposes the [`GetTempPath2`](https://learn.microsoft.com/windows/win32/api/fileapi/nf-fileapi-gettemppath2w) Win32 API, this method invokes that API and returns the resolved path. For more information on how this resolution is performed, including how to control the return value through the use of environment variables, see [the _Remarks_ section](https://learn.microsoft.com/windows/win32/api/fileapi/nf-fileapi-gettemppath2w#remarks) of the GetTempPath2 documentation. The GetTempPath2 API might not be available on all versions of Windows.

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`.
On Windows versions that don't expose GetTempPath2, this method instead invokes the [`GetTempPath`](https://learn.microsoft.com/windows/win32/api/fileapi/nf-fileapi-gettemppathw) Win32 API and returns the resolved path. For more information on how this resolution is performed, including how to control the return value through the use of environment variables, see [the _Remarks_ section](https://learn.microsoft.com/windows/win32/api/fileapi/nf-fileapi-gettemppathw#remarks) of the GetTempPath documentation.

# [Linux](#tab/linux)

1. The path specified by the TMPDIR environment variable.
If the `TMPDIR` environment variable has been set, this method returns the value specified by that environment variable.

2. The path `/tmp/`.
Otherwise, this method returns `/tmp/`.

---

Expand Down