displaying html or other files using their default application
Sometimes, we may want to show user a readme file or start any application or open any document on the system. For openning any file with their default file open handeler, we just have to use following one liner.
System.Diagnostics.Process.Start(@"d:\niran\readme.htm");
You can pass the path to any file or path to any executable and it will be opened like when you double-click on it in windows explorer. In fact, you can also open web addresses using this method in the default browser of the system.
System.Diagnostics.Process.Start(@"http://www.nirandas.com/blog/");
Passing arguments
We can also pass arguments while starting any executable using the second parameter.System.Diagnostics.Process.Start(@"mysql.exe",@"-u root -p");
Here we are starting the application "mysql" and passing it "-u root -p" as command line arguments. The Process.Start() method also takes many other parameters other than discussed here allowing us more finer controll.
You can easily launch files/applications using this one line of code. Enjoy,
If you liked this post, please subscribe to this blog or kick this story on DotNetKicks.com .
