What's the difference between SpecialFolder.Desktop and SpecialFolder.DesktopDirectory?
Asked Answered
C

2

50

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?

Chiastic answered 10/4, 2011 at 14:56 Comment(0)
J
33

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 file system. The desktop folder merges that with virtual items like all users items, recycle bin, shortcut to documents folder etc.

Additional question and answer pulled from comments

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://learn.microsoft.com/en-us/windows/win32/shell/csidl

Ctrl+F for "FOLDERID_Desktop"

Jylland answered 10/4, 2011 at 15:8 Comment(9)
how to configure windows so that the two C# strings show different result?Florineflorio
I don't understand that questionJylland
I tested the C# code, both the two enums return the same value, if they are never different, then it's useless to say the difference of the two enums. So my question is in what scenario does the two enums return different paths?Florineflorio
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 here msdn.microsoft.com/en-us/library/windows/desktop/bb762494.aspxJylland
thanks! so it might be a historical reason for Microsoft to create such two enums.Florineflorio
Looks like it. These enums simply map to csidl values. You can see that the documentation is identical.Jylland
@DavidHeffernan I think your comment answers this well....There is no difference anymore. Would you want to edit, or I can post a new answer.Babb
So, what's the diff in short words?Torrietorrin
@Torrietorrin tl;dr there is no differenceJylland
G
0

The true answer is that those can be different especially width profiles on servers. The user might be running a desktop as from a fileshare, or have it on a local system... If redirected the OS normally doesnt inform other software that it has done that. But if you realy want to get there...

Ginnifer answered 14/11, 2018 at 17:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.