You could use Process.Start
to start the default application for the file type. The clue is to use ProcessStartInfo
the right way. Pass in the file path and name as "application" and set UseShellExecute
to true
.
I tried the following code:
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
ProcessStartInfo si = new ProcessStartInfo();
si.FileName = @"C:\somefile.txt";
si.UseShellExecute = true;
Process.Start(si);
}
This starts Notepad (the default application) with the given file opened and after that ends the application.
Please note that this does not necessarily start Nodepad, but the default application for *.txt files, which may be what you want, as you said you want the same behaviour as if you had double-clicked the file.