[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

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

invoke a file's default application

Sometimes you might want your program to use a default application to open a file. For example, you might want to display a PDF file, web page or URL on the internet.

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

Similarly if the file has a .html extension, the system opens it in your system's 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 a file name 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); }

Download the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.