How to get temporary folder for current user
System.IO.Path.GetTempPath()
is just a wrapper for a native call to GetTempPath(..)
in Kernel32.
Have a look at http://msdn.microsoft.com/en-us/library/aa364992(VS.85).aspx
Copied from that page:
The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:
- The path specified by the TMP environment variable.
- The path specified by the TEMP environment variable.
- The path specified by the USERPROFILE environment variable.
- The Windows directory.
It's not entirely clear to me whether "The Windows directory" means the temp directory under windows or the windows directory itself. Dumping temp files in the windows directory itself sounds like an undesirable case, but who knows.
So combining that page with your post I would guess that either one of the TMP, TEMP or USERPROFILE variables for your Administrator user points to the windows path, or else they're not set and it's taking a fallback to the windows temp path.
Getting user temporary folder path in Windows
Is there a reason you can't use the Win32 GetTempPath API?
- http://msdn.microsoft.com/en-us/library/aa364992(VS.85).aspx
This API is available starting with W2K and hence will be available on all of your listed targets.
How do I open USER Temp Folder, and not Windows TEMP
%USERPROFILE%
expands to "C:\Users\yourusername", so you could try
Environment.ExpandEnvironmentVariables("%USERPROFILE%/AppData/Local/Temp");
Or use the call System.IO.Path.GetTempPath which
checks for the existence of environment variables in the following order and uses the first path found:
The path specified by the TMP environment variable.
The path specified by the TEMP environment variable.
The path specified by the USERPROFILE environment variable.
The Windows directory.
Specifically Getting the System TEMP Path in C#
Perhaps you are looking for the
Environment.GetEnvironmentVariable method.
This usage gives you the user's %TEMP% folder:
Environment.GetEnvironmentVariable("TEMP");
such as
C:\Users\MyUserName\AppData\Local\Temp
And this gives you the system's %TEMP% folder:
Environment.GetEnvironmentVariable("TEMP", EnvironmentVariableTarget.Machine);
such as C:\WINDOWS\TEMP
Get the users temp folder path c++
std::wstring strTempPath;
wchar_t wchPath[MAX_PATH];
if (GetTempPathW(MAX_PATH, wchPath))
strTempPath = wchPath;
Change wstring
to string
, wchar_t
to char
and GetTempPathW
to GetTempPathA
if you're not using Unicode.
In a .Net winforms application, how do I obtain the path the current user's temp folder?
Use System.IO.Path.GetTempPath()
.
Related Topics
Best Way to Resolve File Path Too Long Exception
Decompressing Gzip Stream from Httpclient Response
How to Set Extended File Properties
Is a Memory Leak Created If a Memorystream in .Net Is Not Closed
How to Get All Constants of a Type by Reflection
Why Do C# Multidimensional Arrays Not Implement Ienumerable<T>
Combining N Datatables into a Single Datatable
What Is the Memory Overhead of a .Net Object
Capture a Keyboard Keypress in the Background
Is the Order of Static Class Initialization in C# Deterministic
How to Find Control in Templatefield of Gridview
Why Does This Floating-Point Calculation Give Different Results on Different MAChines