How to get a path to the desktop for current user in C#?


Question

How do I get a path to the desktop for current user in C#?

The only thing I could find was the VB.NET-only class SpecialDirectories, which has this property:

My.Computer.FileSystem.SpecialDirectories.Desktop

How can I do this in C#?

1
321
8/12/2011 12:56:47 PM

Accepted Answer

string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
722
3/11/2009 11:25:21 AM

 string filePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
 string extension = ".log";
 filePath += @"\Error Log\" + extension;
 if (!Directory.Exists(filePath))
 {
      Directory.CreateDirectory(filePath);
 }

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon