How to programmatically derive Windows Downloads folder “%USERPROFILE%/Downloads”?

Yes it is special, discovering the name of this folder didn’t become possible until Vista. .NET still needs to support prior operating systems. You can pinvoke SHGetKnownFolderPath() to bypass this limitation, like this: using System.Runtime.InteropServices; … public static string GetDownloadsPath() { if (Environment.OSVersion.Version.Major < 6) throw new NotSupportedException(); IntPtr pathPtr = IntPtr.Zero; try { SHGetKnownFolderPath(ref … Read more

Application’s data folder in Mac

/Users/USERNAME/Library/Application Support/ Edit: This answer has drawn a lot of upvotes despite its minimalistic nature. Therefore, I want to point out the things mentioned in the comments here to make them more visible: There are several other folders being used for application data / configuration, as mentioned in this answer. If writing an application, don’t … Read more

What’s the difference between SpecialFolder.Desktop and SpecialFolder.DesktopDirectory?

Answer to original question A directory is a location in the file system. A folder is a location in the shell namespace. A directory is a kind of folder. A virtual folder is not necessarily backed by a directory. For example consider libraries or search folders. The user’s desktop directory is a location in the … Read more

Is There A System Defined Environment Variable For Documents Directory?

For powershell the following works: [environment]::getfolderpath(“mydocuments”) and avoiding magic strings [Environment]::GetFolderPath([Environment+SpecialFolder]::MyDocuments) For .NET the following holds true (ie not applicable in all windows applications): As one answer points out, there is no Environment Variable pointing to My Documents but there is Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) (C#) for .NET. I’m adding this answer since this question comes up when … Read more

What determines the return value of Path.GetTempPath()?

(Using Reflector) Path.GetTempPath() ultimately calls the Win32 function GetTempPath (from kernel32.dll). The MDSN docs for this state: 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 … Read more

Getting Downloads Folder in C#? [duplicate]

The Downloads folder is a so called “known” folder, together with Documents, Videos, and others. Do NOT: combine hardcoded path segments to retrieve known folder paths assume known folders are children of the user folder abuse a long deprecated registry key storing outdated paths Known folders can be redirected anywhere in their property sheets. I’ve … Read more

Environment.GetFolderPath(…CommonApplicationData) is still returning “C:\Documents and Settings\” on Vista

My installer copied a log.txt file which had been generated on an XP computer. I was looking at that log file thinking it was generated on Vista. Once I fixed my log4net configuration to be “Vista Compatible”. Environment.GetFolderPath was returning the expected results. Therefore, I’m closing this post. The following SpecialFolder path reference might be … Read more