Alwyn
Alwyn

Reputation: 8337

How to launch default application for an arbitrary file in .net?

How can I start the default program for an arbitrary file from .net?

Eg if I have a FileInfo reference to a .mp3 music, I want to launch Windows Media Player (if that's set up as the default handler for the file type)

Consequently if I have .xls, I want to launch Excel with the file pre-opened.

How can I do this from code?

Upvotes: 1

Views: 2079

Answers (2)

SLaks
SLaks

Reputation: 887195

You can simply call Process.Start(path) to open any file in the default program.

Upvotes: 4

germi
germi

Reputation: 4658

Just use Process.Start (MSDN-article)

Process.Start(pathToYourFile);

Windows will launch the appropriate application. Just watch out: Up until Windows 8, this will throw an exception, if there is no standard application for that file type.

Upvotes: 10

Related Questions