views:

38

answers:

3

Hi, it is possible to do a request for another page on internet from page_load? I mean if it is possible to aquire markup code with informations from another page and display them on my aspx site? For example something like this:

protected void Page_Load(object sender, EventArgs e)
{
  UnknownType anotherSite = GetMarkupCode("www.fifa.com");
  //parse anotherSite
             .
             .
             .
  //display parsed informations
             .
             .
             .
}

If it is possible how can i do that? Many thanks for answers.

+1  A: 

Why don't you use an iframe and set the source of the iframe as the requested page url?

rahul
My "assumption" is that he wants to parse the html in order to retrieve certain bits of information from it. Not just display the whole page in an iframe.
Robin Day
yes you are right
sanjuro
+3  A: 

User can use the WebClient class.

WebClient webClient = new WebClient();
Stream data = webClient.OpenRead("http://www.fifa.com");
StreamReader streamReader = new StreamReader(data);
string html = streamReader.ReadToEnd();

EDIT: A simpler version thanks to Lucas

WebClient webClient = new WebClient();
string html = webClient.DownloadString("http://www.fifa.com");
Robin Day
In this case, it's simpler to use just `string html = webClient.DownloadString("http://www.fifa.com");`, rather that open it as a stream.
Lucas Jones
Thanks! I had no idea that was there! Not used WebClient in a while. Have edited answer to include.
Robin Day
Perfect this is exactly what i want :) Thanks Robin Day and also Lucas Jones.
sanjuro