Results 1 to 2 of 2

Thread: How to retrieve a html source from a URL?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    Question How to retrieve a html source from a URL?

    Hello!

    I have a URL of a web page and I want to recieve the html source of that page in a string using c#.
    how can I do that?

    thanks!

    Dekel C.

  2. #2
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Re: How to retrieve a html source from a URL?

    You can use the System.Net.WebClient class.

    Code:
    using System.Net;
    using System.IO;
    
    // ...
    
    // create a new WebClient
    WebClient client = new WebClient();
    
    // create a stream which contains the source of the address passed.
    Stream webStream = client.OpenRead(@"http://www.google.com");
    StreamReader reader = new StreamReader(webStream);
    // read the entire stream
    string value = reader.ReadToEnd();
    // show the source
    MessageBox.Show(value);
    // clean up
    webStream.Close();
    reader.Close();
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width