C#: Launch URL from inside a windows application

Hi,

 

I am new to C#, and was wondering if someone could provide sample code for launching a default website from within a windows form I have a userform with various buttons. I would like to click on a button and then launch the desired intranet website. I poked around the web and this is what I have found:-

 

Private void button8_Click(object sender, EventArgs e)

{

string targetURL = @http://www.duncanmackenzie.net;

System.Diagnostics.Process.Start(targetURL);

}

Any help is much appreciated.

 

 



Answer this question

C#: Launch URL from inside a windows application

  • YeeBoon

    ok

    In that case 1 method to do this is how you have the above code, with a minor adjustment to the string targetUrl.

    string url = "http://www.google.com";

    should work for you.


  • Henry Bromelkamp

    Hi UsingBytes,

    I would like the end users browser to pop up with the specified url. I plan on publish my app to the end users machine, if that helps

    Thanks.


  • arro239

    Hello,

    How are you wanting this to be implemented

    Are you using a browser control in your form (a web browser will open within your application)

    Or are you wanting to use the end-users browser (form will use external browser)


  • MISW

    Hi,

    So I should try the following:

    private void button8_Click(object sender, System.EventArgs e)

    {

    string url = "http://www.google.com";

    System.Diagnostics.Process.Start(url);

    }

    Thanks.


  • Rama Boya

    Yes that should work for you.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Net;

    namespace Test
    {
    public partial class Form1 : Form
    {
    private string url = http://www.google.com;

    public
    Form1()
    {
    InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
    System.Diagnostics.
    Process.Start(url);
    }
    }
    }

    Essential you were correct, you just need to remove the @ symbol


  • Chris Marts

    Thank you. That worked perfectly!

    Cheers.


  • C#: Launch URL from inside a windows application