-1

enter image description here

I tried

Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

they both return same results

TaW
  • 53,122
  • 8
  • 69
  • 111
jack
  • 181
  • 3
  • 11
  • 6
    Those should work. What makes you think they don't? – canton7 Jul 02 '20 at 15:41
  • I am trying to get desktop directories like in the above picture. – jack Jul 02 '20 at 15:50
  • `var dd = Directory.GetDirectories( Environment.GetFolderPath(Environment.SpecialFolder.Desktop) );` – TaW Jul 02 '20 at 15:51
  • And what do those methods you listed return, and how is that different to what you expect? – canton7 Jul 02 '20 at 15:52
  • 1
    My Documents does not exist as a subdirectory of the Desktop folder on disk. If you want this tree specifically I think you'd need to get it from the Windows Shell API, but I don't know exactly how. – Rup Jul 02 '20 at 15:54
  • those methods don't return My Documents and others – jack Jul 02 '20 at 15:57
  • Here's an MSDN article that calls this [the Shell Namespace](https://learn.microsoft.com/en-us/windows/win32/shell/namespace-intro). There's no C# code there though. – Rup Jul 02 '20 at 16:02

1 Answers1

0

This image in the question representing a Windows File Explorer view of the Desktop root item is a virtual view constructed by the explorer.

As I know it has no physical existence on the drive and its content varies with the Windows version from 95 to 10.

The Desktop folder in the User folder on the drive only contains links and files shown on the screen (the desktop).

Perhaps there is a WinAPI to get such list but I don't know. Perhaps it is somewhere in the registry. Perhaps you can found something with Explorer-like implementations.

How to create an Explorer-like folder browser control?

https://www.c-sharpcorner.com/UploadFile/17e8f6/windows-explorer-in-C-Sharp-net/

https://www.codeproject.com/Articles/15059/C-File-Browser

https://learn.microsoft.com/en-us/windows/win32/shell/folder-info

  • 1
    I think your third link, the CodeProject C# File Browser, is the correct one, particularly [the Shell classes](https://www.codeproject.com/Articles/15059/C-File-Browser#TheShellclasses). It is for an old version of .NET, though, so might not just work out of the box. – Rup Jul 02 '20 at 16:43