Search code examples
c#special-folders

C# reference to the desktop


I am using a file stream to write out a file.

I was hoping to be able to write the file to the desktop.

If I have something like

tw = new StreamWriter("NameOflog file.txt");

I would like to be able to have some sort of @desktop identified in front of the file name that would automatically insert the path to the desktop.

Does this exist in C#? Or do I have to look for desktop paths on a computer by computer (or OS by OS) basis?


Solution

  • Quick google search reveals this one:

    string strPath = Environment.GetFolderPath(
                             System.Environment.SpecialFolder.DesktopDirectory);
    

    EDIT: This will work for Windows, but Mono supports it, too.