Email: Password:       Forgot Password 
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.

Read a Remote Web Page in ASP.NET

Viewed:  1046 
Posted On:  21/02/2015 23:16:30 
How we can read a web page in c#? 

In this article I am going to explain how we can read a remote web page in c#.

Below is my aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <asp:Label ID="lblResponse" runat="server"></asp:Label></div>

Now my aspx.cs is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        string URLResponse = GetHtmlPage("");
        lblResponse.Text = URLResponse;
    static string GetHtmlPage(string strURL)
        String strResult;
        WebResponse objResponse;
        WebRequest objRequest = HttpWebRequest.Create(strURL);
        objResponse = objRequest.GetResponse();
        using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
            strResult = sr.ReadToEnd();
        return strResult;


Here I am reading and showing response in a label:


Image 1.

         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us