Get path from the desktop

1

Good, last week I put a question here:

Automatically save to a default folder C #

I have now created another form, and I want it in Load to automatically fetch the file from the Desktop. But I can not put the code below, because if the program was installed on other machines, the program will give an error. How do I put the code to go to the Desktop?

CODE

  System.Diagnostics.Process.Start(@"C:\Users\NOME\Desktop\File.txt");

Thank you!

    
asked by anonymous 22.05.2015 / 12:38

1 answer

3

Uses the enum Environment.SpecialFolder.Desktop

string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string filePath = Path.Combine(desktop, "File.txt");
    
22.05.2015 / 12:41