mdibb.net

Loading URLs and Files with their default application in C#

From time to time you need to open a URL or file or something else from within your application, for example I've recently been working on a generic "About Box" for my freeware software that has a link to this site in it, the idea being that they click on the link and they get their default browser come up and navigate to it for them. But how do we do that?

Actually its absurdly simply - this is the sort of functionality that really sets .Net apart in my opinion. In the old days you had to do all sorts of rubbish like extract the file type, go rummaging through the registry, and maybe even using DDE!

Using .Net, you can open any file or site like you would by using "Run" in the start menu - i.e. you can provide a path and filename, or you can provide a URL provided that you begin with the correct protocol identifier such as "http://" or "ftp://" for example.

Loading an example URL in C#

Ok so having said that, lets consider an example. Lets see how we'd get our default browser to load up this site:

System.Diagnostics.Process.Start("http://www.mdibb.net");
Thats all there is to it! You can swap out that URL for a filename or any other url if you want. Provided that the Windows installation you are running your code on knows how to handle the file or URL provided, you'll get the default application load up to deal with it, even something like getting Skype to load up by providing a suitable "callto://" URL.

Back 17.06.2006.