Category : C# | Author : Chtiwi Malek | First posted : 6/15/2012 | Updated : 12/8/2012
Tags : winforms, c#, .net, url, launch, open, browser, programatically, link
Open an URL in browser from C# Winforms

Open an URL in browser from C# Winforms

This code will allow you to launch the default browser on the system and open an URL.

To do this we need to retrieve the path of default browser from windows registry, then we launch a process with the link as argument :
using System.Diagnostics;
using System.IO;
using Microsoft.Win32;
	
private void OpenURL(string url)
{
   string key = @"htmlfile\shell\open\command";
   RegistryKey registryKey = Registry.ClassesRoot.OpenSubKey(key, false);
   // Get the default browser path on the system
   string Default_Browser_Path = ((string)registryKey.GetValue(null, null)).Split('"')[1];

   Process p = new Process();
   p.StartInfo.FileName = Default_Browser_Path;
   p.StartInfo.Arguments = url;
   p.Start();
}
	
private void button1_Click(object sender, EventArgs e)
{
   OpenURL("http://www.codicode.com");
}
Comments & Opinions :
hfgh
hfg
- by yrt on 10/9/2019
hfgh
hfg
- by yrt on 10/9/2019
mrs
dasd
- by yrt on 10/9/2019
Leave a Comment:
Name :
Email : * will not be shown
Title :
Comment :