Article ID: 306222 - Last Review: December 11, 2006 - Revision: 2.2 How to use a file name to start an application by using Visual C#
This article was previously published under Q306222 On This PageSUMMARY
This step-by-step article shows you how to start the application that is associated with a given document extension or file type without needing to know the name or location of the associated application. For example, you can start Arcade.bmp with the application that is associated with the .bmp file extension, which is MSPaint.exe in most cases. Requirements
Include NamespacesThe namespace must appear before the class declaration, as follows:Specify the ProcessStartInfo InformationYou can use the ProcessStartInfo structure of the .NET Framework Process class to specify options when you start a process. This article outlines how to use the file name option. Another member, UseShellExecute, specifies that the process be started based on a file extension or file type instead of the name of the executable (.exe). This property is set to true by default. It is set explicitly in this code for illustrative purposes.Start the ApplicationThis example opens a file named Eula.txt. The file is opened with the application that is associated with the .txt file extension, which is normally Notepad.exe. You can substitute any file name or type that has an associated application.Shortcut to Start the ApplicationBecause UseShellExecute is true by default, you are not required to use ProcessStartInfo when you start a process. You can start the associated application with a single line of code, as follows:Complete Code SampleTroubleshootingIt is possible that an individual computer may not have the associated application installed, or the associations in the registry may not be correct. It is best to wrap this code in a try...catch block so that your application is alerted in the event of a failure.
| Other Resources Other Support Sites
CommunityGet Help NowArticle Translations
|






Windows Live
Facebook
Twitter
Linkedin
Digg it
Yahoo
Delicious
StumbleUpon
Yammer
Reddit
Technorati
FriendFeed
Email
Back to the top
