Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. String to URL

String to URL

Scheduled Pinned Locked Moved C#
questionhtml
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dsl fahk
    wrote on last edited by
    #1

    I'm currently working on a simple web browser, but i can't get the simplest thing: how do i convert the text in my text box to type system.url? the web browser works and when i click a link the text box is updated, but i cannot get what's in the text box to go back to the web browser (which should be operated by a button). Thanks in advance. P.S. I am thinking the next thing i will try to add will be the source HTML. What property do i have to check to get this? Or what method should i use?

    J 1 Reply Last reply
    0
    • D dsl fahk

      I'm currently working on a simple web browser, but i can't get the simplest thing: how do i convert the text in my text box to type system.url? the web browser works and when i click a link the text box is updated, but i cannot get what's in the text box to go back to the web browser (which should be operated by a button). Thanks in advance. P.S. I am thinking the next thing i will try to add will be the source HTML. What property do i have to check to get this? Or what method should i use?

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      I assume you mean System.Uri, not System.Url.

      Uri uri = new Uri(textBox.Text);

      Alternately, you can use the TryCreate static method of the Uri class to attempt to create a URI. Unlike the above method, which throws an exception if the text of the text box is not a valid URI (for instance, if you forgot to type the "http://" part of www.google.com), TryCreate will tell you if it's a valid URI without throwing any errors:

      Uri validUri;
      bool isValidUri = Uri.TryCreate(textBox.Text, UriKind.Absolute, out validUri);
      if(isValidUri)
      {
      // Now you can use validUri object.
      }

      p.s. You don't need to convert the text to System.Uri in order to call webBrowser.Navigate. Look at the System.Navigate method overloads[^], notice that one of them takes a string. With that, you can just call

      browser.Navigate(textBox.Text);

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: Guess who's having a birthday? (It's not Jesus) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      D 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        I assume you mean System.Uri, not System.Url.

        Uri uri = new Uri(textBox.Text);

        Alternately, you can use the TryCreate static method of the Uri class to attempt to create a URI. Unlike the above method, which throws an exception if the text of the text box is not a valid URI (for instance, if you forgot to type the "http://" part of www.google.com), TryCreate will tell you if it's a valid URI without throwing any errors:

        Uri validUri;
        bool isValidUri = Uri.TryCreate(textBox.Text, UriKind.Absolute, out validUri);
        if(isValidUri)
        {
        // Now you can use validUri object.
        }

        p.s. You don't need to convert the text to System.Uri in order to call webBrowser.Navigate. Look at the System.Navigate method overloads[^], notice that one of them takes a string. With that, you can just call

        browser.Navigate(textBox.Text);

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: Guess who's having a birthday? (It's not Jesus) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

        D Offline
        D Offline
        dsl fahk
        wrote on last edited by
        #3

        Thanks. It works!:) and I did mean URI, thanks for telling me. So do you know how I could access the HTML of the webBrowser? Thanks.

        J 1 Reply Last reply
        0
        • D dsl fahk

          Thanks. It works!:) and I did mean URI, thanks for telling me. So do you know how I could access the HTML of the webBrowser? Thanks.

          J Offline
          J Offline
          jk chan
          wrote on last edited by
          #4

          pls look axWebBrowser1.Document (IHTMLDocument's type) .

          If u can Dream... U can do it

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups