1

I am trying to create a folder in the Desktop (Using DirectoryInfo) - I need to get the Desktop path

I've tried using:

DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)

But it keeps getting me into the user's Folder (Where the Desktop, Music, Vidoes folders are).

DirectoryInfo dir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "Folder111" );
dir.Create();
Emma
  • 27,428
  • 11
  • 44
  • 69

2 Answers2

5

You aren't formatting the path correctly. You're just tacking on the new folder name to the desktop folder name. So if the desktop folder is at C:\Users\MyUsername\Desktop, you are creating a folder called C:\Users\MyUsername\DesktopFolder111, when what you really want is C:\Users\MyUsername\Desktop\Folder111 (you're missing the slash).

Use Path.Combine() to automatically add the slash for you:

DirectoryInfo dir = new DirectoryInfo(
    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Folder111"));

Daniel's answer may also be applicable.

Gabriel Luci
  • 38,328
  • 4
  • 55
  • 84
1

You want DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) See: What's the difference between SpecialFolder.Desktop and SpecialFolder.DesktopDirectory?

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445