Friday, June 5, 2009

How to open other website URL content in my aspx page




Please visit my new Web Site https://coderstechzone.com



Few days ago i have a requirement that client wants to display category wise sites in his home page. To do that at first what i need? I need to display an external URL or website in my aspx page. After a short search i found an example on this by devasp. For your learning i want to share the code with you.

Add the panel into your aspx page :
<asp:panel id="mainpanel" BorderStyle="Dotted" BorderColor="orange" BorderWidth="2"
style="POSITION: absolute;top:3px;left:3px" runat="server" Width="99%"></asp:panel>


protected void Page_Load(object sender, EventArgs e)
{
Uri weburi = new Uri(http://www.gmail.com/);
StringBuilder str = new StringBuilder();
string temp = "";
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(weburi);
HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
StreamReader webstream = new StreamReader(webresponse.GetResponseStream(), Encoding.ASCII);
while ((temp = webstream.ReadLine()) != null)
str.Append(temp +
"\r\n");
webstream.Close();
mainpanel.Controls.Add(
new System.Web.UI.LiteralControl(str.ToString()));
}
* Don't forget to add namespace: using System.Text;using System.Net;using System.IO;

Output:


Common Error:
1. Invalid URI: The format of the URI could not be determined.
Solution:
Supply full URL like http://www.gmail.com/ instead of http://www.gmail.com/

2 comments:

Anonymous said...

sir i want to talk to you.. is it possible... please replay me.. to.rohan@yahoo.com

Anonymous said...

error in Uri
weburi = new Uri(http://www.gmail.com/);

(invalid expression terms ':') after http:

help me please

Want to say something?
I WOULD BE DELIGHTED TO HEAR FROM YOU

Want To Search More?
Google Search on Internet
Subscribe RSS Subscribe RSS
Article Categories
  • Asp.net
  • Gridview
  • Javascript
  • AJAX
  • Sql server
  • XML
  • CSS
  • Free Web Site Templates
  • Free Desktop Wallpapers
  • TopOfBlogs
     
    Free ASP.NET articles,C#.NET,VB.NET tutorials and Examples,Ajax,SQL Server,Javascript,Jquery,XML,GridView Articles and code examples -- by Shawpnendu Bikash