Internet Explorer in C#

Hello,

First of all, I am very thankful for these forums and I am glad you guys are here to help! Anyway, I have Visual Studio 2005 Express C# Edition and I am working on a program and let me explain what I need to do. Okay, so I am working on this program. I was talking to the head manager on this and he said here is what we need. We need to have one text box and one button to load a website. Inside the text box the user will type the URL in. When the button is clicked on, it will load the URL from the text box. How can I do this

Paul




Answer this question

Internet Explorer in C#

  • mrodriguezc

    Hi!

    Simple, use WebBrowser control, Button and TextBox controls on your form. On button's Click event do this:

    webBrowser.Navigate(textBox.Text)



  • Ken Schall

    Ups, I forget about UseShellExecute:

     

    process.StartInfo.UseShellExecute = true;

    process.StartInfo.FileName = TextBox.Text;



  • KCTami

    If you want to open page in IE - use this:

    System.Diagnostics.Process process = new System.Diagnostics.Process();

    process.StartInfo.FileName = URI;

    process.Start();



  • CHowell

    Sergey,

    That worked fine, thanks!

    For people reading those posts in the future, you need to assign the "mailto:..." string described by Sergey to the Process.StartInfo.Filename Property described in an earlier post.

    MM.


  • Shailesh Saini

    Inside button's Click event handler. If you want open URL in Internet Explorer - use System.Diagnostics.Process, if you have own embedded browser - Navigate() method.

     

    P.S. If you are new to Visual Studio - double click button in designer to create event handler.



  • JohnsonZhang

    And what if I wanted to supply login credentials using a POST method
    Is that possible

  • EricPaul

    Hey,

    Thanks so much!!!!!!!!!!! That worked!

    Paul



  • victoriak68

    Hi!

    a) UseShellExecute force to start process by scanning registry for file type or protocol you use. So if you type there "sample.doc" it will understand to run Word (or other program assigned to handle given extension). So, if user have FireFox as primary browser, it will start FireFox, not IE.

    b) use mailto: protocol, like this "mailto:someone@somewhere.com", it will open user's mail client with empty mail to given address. You can also do this: "mailto:someone@somewhere.com subject=HELLO".



  • Ben0s

    Hello,

    That was a great suggestion! I already know that though. I need it to open Internet Explorer.

    Paul



  • AllanP

    I mean (replace TextBox with name of your text box):

    System.Diagnostics.Process process = new System.Diagnostics.Process();

    process.StartInfo.UseShellExecute = true;

    process.StartInfo.FileName = TextBox.Text;

    process.Start();



  • Steve Tyson

    Hello,

    Thanks! Here are the errors when I copied and pasted:

    Error 1 The name 'process' does not exist in the current context C:\Documents and Settings\Paul Rosenthal\My Documents\Visual Studio 2005\Projects\Gadgets\Gadgets\Form1.cs 185 13 Gadgets
    Error 2 An object reference is required for the nonstatic field, method, or property 'System.Windows.Forms.Control.Text.get' C:\Documents and Settings\Paul Rosenthal\My Documents\Visual Studio 2005\Projects\Gadgets\Gadgets\Form1.cs 185 42 Gadgets

    Paul



  • Scott W.

    Hi,

    I used your snippet to open IE and navigate to the right url based on the text value of a link label and it worked great.

    However :

    a- I can't figure out how the system 'knows' to use IE since nothing in your code specifies what executable to use for the process. I won't lose sleep over it but I'd like to know.

    b- I tried doing the same thing to start the default mail client with a blank email but the right 'to' address populated without success.

    What I'd like is to have a link label with the email address on a form and when clicked the default mail client on the machine running the app pops up with a new email message with already the right address.

    I tried your code, just replacing the url with the email address and it caused an exception, and I don't want to have to specify the name of an exe since I don't know what client machines may be using for mail.

    Any suggestion would be appreciated.

    Thanks,

    MM


  • Matt_chrs

    Hello,

    So I just copied and pasted the code and it didn't work. It said "No URI file". Please help.

    Paul



  • Mudasir

    Hi,

    Thanks for the reply! Where would I use this I mean where would I use the code you gave me

    Paul



  • Internet Explorer in C#