===========================================
using System.Diagnostics;
using Microsoft.Win32;
//
//
public void OpenUrl(string url) {
try
{
string targetURL = url;
Process p = new Process();
//
p.StartInfo.FileName = getMyDefaultBrowser();
p.StartInfo.Arguments = targetURL;
p.Start();
}
catch (Exception err)
{
MessageBox.Show("Problem : " + err.Message);
}
}
//
//To access registry key please use the namespace Microsoft.Win32
private string getMyDefaultBrowser() {
string browser = string.Empty;
RegistryKey myKey = null;
try
{
mykey = Registry.ClassesRoot.OpenSubKey(@"HTTP\shell\open\command", false);
browser = mykey.GetValue(null).ToString().ToLower().Replace("\"", "");
if (!browser.EndsWith("exe"))
{
browser = browser.Substring(0, browser.LastIndexOf(".exe") + 4);
}
}
finally
{
if (mykey != null) mykey.Close();
}
return browser;
}
1 comment:
You dont have to write that much code.
here is cod that works fine..
System.Diagnostics.Process.Start("http://www.google.com");
Regards,
Jalpesh
http://jalpesh.blogspot.com
Post a Comment