Jayant Bramhankar
Jayant Bramhankar

Reputation: 378

How to load other web page in ASP.NET

I want to load some fixed part from other website to my web application. How to accomplish this? Thanks.

Upvotes: 5

Views: 8587

Answers (2)

Gideon
Gideon

Reputation: 18501

You could do it in a few ways:

  1. On the client side, load the content into an <iframe>
  2. On the client side, load the content using ajax and write it into the page.
  3. On the server side, load the page using WebClient DownloadString and write it into your page.

Update

After you get your string, you might parse it and grab the stuff you want using the Html Agility Pack . (Also available on Nuget)

Upvotes: 6

Shadow Wizzard
Shadow Wizzard

Reputation: 66398

You can use WebRequest for this task:

string url = "http://somesite.com/somepage.php";
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
    string contents = reader.ReadToEnd();
    //parse contents as you wish.......
    reader.Close();
}
response.Close();

Upvotes: 5

Related Questions