Related Posts Plugin for WordPress, Blogger...

About

Follow Us

Saturday, 9 November 2013

How to display information from another website in asp.net


Introduction: In this article you will come to know How to display the website content from another website in asp.net.
Implementation:
In the design page (.aspx) design the page as below:
<div>
    <span style="font-family: Verdana, sans-serif;"> 
<asp:label id="lblDisplay" runat="server"></asp:label></span> 
    </div>


ASP.NET code to Display other website Content:

Using C#.Net:
In the code file (.aspx.cs) code as:

using System.Net;
using System.IO; 

  protected void Page_Load(object sender, EventArgs e)
    {
        WebRequest wReq = WebRequest.Create("http://www.maziksolutions.com");
        WebResponse mRes = wReq.GetResponse();
        StreamReader sr = new StreamReader(mRes.GetResponseStream());
        string sHTML = sr.ReadToEnd();
        sr.Close();
        mRes.Close();

        if (sHTML != string.Empty && sHTML != null)
        {
            lblDisplay.Text = sHTML;
        } 
    }

VB.Net Code

In the code file (.aspx.vb) code as:

Imports System.IO
Imports System.Net
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Dim wReq As WebRequest = WebRequest.Create("http://www.maziksolutions.com")
        Dim mRes As WebResponse = wReq.GetResponse()
        Dim sr As New StreamReader(mRes.GetResponseStream())
        Dim sHTML As String = sr.ReadToEnd()
        sr.Close()
        mRes.Close()

        If sHTML <> String.Empty AndAlso sHTML IsNot Nothing Then
            lblDisplay.Text = sHTML
        End If
    End Sub


Categories: , , ,

0 comments:

Post a Comment