Return to Snippet

Revision: 59726
at September 26, 2012 23:13 by Verician


Updated Code
using System.Diagnostics;
using Microsoft.Win32;


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


static public void openBrowser(string theURL)
        {
            string defaultBrowserPath = GetDefaultBrowserPath();
            try
            {
                Process.Start(defaultBrowserPath, theURL);
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message);
                System.Diagnostics.EventLog.WriteEntry("ERROR", exp.Message, System.Diagnostics.EventLogEntryType.Error);
            }
        }

Revision: 59725
at September 26, 2012 23:10 by Verician


Initial Code
using System.Diagnostics;
using Microsoft.Win32;


static public void openBrowser(string theURL)
        {
            string defaultBrowserPath = GetDefaultBrowserPath();
            try
            {
                Process.Start(defaultBrowserPath, theURL);
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message);
                System.Diagnostics.EventLog.WriteEntry("ERROR", exp.Message, System.Diagnostics.EventLogEntryType.Error);
            }
        }

Initial URL

                                

Initial Description
I needed to open a browser window from my small C# app as a result of a dynamic URL build from data received from the command line. This did the trick!

Initial Title
Open Web Browser Window to URL C#

Initial Tags
url, browser, web

Initial Language
C#