/ Published in: C#
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!
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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); } }