Open a file with the system's default application in C#

The System.Diagnostics.Process class's Start method starts the application that the system associates with a file. For example, if the file has a .txt extension, then the system opens it in NotePad, WordPad, or whatever program is associated with .txt files.

Similarly if the file has a .html extension, the system opens it in the default browser. Note that the file can be a URL such as http://www.csharphelper.com or even just www.csharphelper.com.

In this example, when you select a file name from the ComboBox or type one of your own and click Open, the program uses the following code to open the file.

// "Start" the file.
private void btnOpen_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(cboFile.Text);
}

   

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments

Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.