1

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?

Alwyn
  • 8,079
  • 12
  • 59
  • 107
  • [This](http://stackoverflow.com/questions/11365984/c-sharp-open-file-with-default-application-and-parameters) [seems](http://stackoverflow.com/questions/162331/finding-the-default-application-for-opening-a-particular-file-type-on-windows/162351#162351) [easily](http://www.csharp-examples.net/open-file-with-default-application/) [googlable](https://www.google.com/search?q=launch+default+application+c%23&oq=launch+default+application+c%23&aqs=chrome..69i57j69i60j0l4.5633j0j4&sourceid=chrome&espv=210&es_sm=93&ie=UTF-8) – crthompson Oct 24 '13 at 15:23
  • I'll mark this question back up because it's quite possible the google search will lead you to this question. – asmith1024 Jan 09 '20 at 00:33

2 Answers2

10

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.

germi
  • 4,628
  • 1
  • 21
  • 38
4

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

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964