Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying a relative path

I have a windows forms project. In the current directory I have a Help folder with *.chm files. What is the easiest way to launch them from the application? How can I specify the relative path to them?

like image 326
Peter17 Avatar asked Feb 22 '11 11:02

Peter17


1 Answers

The Environment.CurrentDirectory property will be set to the location of your .exe file. So if you place your help folder in there, it will be:

// The path to the Help folder.
string directory = Path.Combine(Environment.CurrentDirectory, "Help"); 

// The path to the Help file.
string filePath = Path.Combine(directory , "myHelpFile.chm"); 

// Launch the Help file.
Process.Start(filePath); 

EDIT: I should say, that Environment.CurrentDirectory points to the folder where the process started by default in a Windows Forms application, but its value can be changed by some controls (like the OpenFileDialog - see here for a workaround) during the lifetime of your application. Under a Windows Service, Environment.CurrentDirectory maps to the %SystemDirectory%.

like image 196
sheikhjabootie Avatar answered Oct 12 '22 23:10

sheikhjabootie