Friday, November 27, 2009

How to open URL in IE browser by using c#.net

First we have to add the following namespace....

using System.Diagnostics;
using System.IO;
using Microsoft.Win32;


private static string GetDefaultBrowserPath()
{
string key = @"htmlfile\shell\open\command";
RegistryKey registryKey = Registry.ClassesRoot.OpenSubKey(key, false);
// get default browser path
return ((string)registryKey.GetValue(null, null)).Split('"')[1];
}

private void button1_Click(object sender, EventArgs e)
{
string url = "www.google.com";
Process p = new Process();
p.StartInfo.FileName = GetDefaultBrowserPath();
p.StartInfo.Arguments = url;
p.Start();
}

No comments:

Post a Comment