CSharp - Write program to Get the Path to the Desktop


When you work with files, you might want to create a file on the user's desktop.

find that path to the desktop.


You can use the Environment object.

The value of Desktop is one of the values of an enumeration called Environment.SpecialFolder.


using System;

class Program//from   w  w w. j a va 2s  .  c  o  m
    static void Main(string[] args)
        // Finding path to the desktop 
        string pathToDesktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

        // Output 
        Console.WriteLine("Path to your desktop: " + pathToDesktop);