I'm confused about the differences between these two special folders.
Here's a code snippet that writes the output of each, but they output the same thing.
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string pathTwo = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); Console.WriteLine(path); Console.WriteLine(pathTwo); Console.ReadKey();
According to the MSDN documentation (for .NET 1.1):
Desktop
The logical Desktop rather than the physical file system location.
DesktopDirectory
The directory used to physically store file objects on the desktop. Do not confuse this directory with the desktop folder itself, which is a virtual folder.
What does it mean when it says the logical Desktop rather than the physical file system location
? Also, what is a virtual folder
in simple terms?
In the newer .NET 4 version of the documentation, I noticed that they removed the Desktop
entirely and only left DesktopDirectory
. Why is this?
Special folders are set by default by the system, or explicitly by the user, when installing a version of Windows. The Environment. GetFolderPath method returns the locations associated with this enumeration.
On Microsoft Windows, a special folder is a folder that is presented to the user through an interface as an abstract concept instead of an absolute folder path. (The synonymous term shell folder is sometimes used instead.)
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 file system. The desktop folder merges that with virtual items like all users items, recycle bin, shortcut to documents folder etc.
Question (by Lei Yang) Why is the following always true:
Environment.GetFolderPath(Environment.SpecialFolder.Desktop) == Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
Answer (by David Heffernan):
The answer addresses the two specific questions asked. It doesn't attempt to address the issue you raise. If you look at the two CSIDL enum values that correspond to the two .net special folder values you will see that they map to the same known folder guid. This suggests to me that in older versions of Windows there was a difference but that has changed.
See https://docs.microsoft.com/en-us/windows/win32/shell/csidl
Ctrl+F
for "FOLDERID_Desktop"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With