Steve Lydford on .Net

Sticking all my useful bits in one place in the hope that I may find them again one day!
posts - 4, comments - 0, trackbacks - 0

My Links

News

Hi. This just a collection of useful bits and pieces that I am posting here so that I might be able to find them again in the future. Feel free to browse through and use anything that may be of some help to you.

Archives

Post Categories

Open Page in Default Browser From Code

This code uses the System.Diagnostics namespace to open a specified URL in the users default web browser. There is some error checking in there incase the user has no default browser, so it should be fairly robust.

The following code is the Click event of a LinkLabel called linkLabel1:

       
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string webURL = "http://geekswithblogs.net/stevelydford";
 
            try
            {
                System.Diagnostics.Process.Start(webURL);
            }
            catch
                (
                 System.ComponentModel.Win32Exception noBrowser)
            {
                if (noBrowser.ErrorCode == -2147467259)
                    MessageBox.Show(noBrowser.Message);
            }
            catch (System.Exception other)
            {
                MessageBox.Show(other.Message);
            }
 
        }

Print | posted on Monday, May 12, 2008 11:02 PM | Filed Under [ C# ]

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 1 and 4 and type the answer here:

Powered by: