Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

FREE 12 month online training for ASP.NET & MS Expression Studio and a Free copy of MS Expression Web with Windows Server Purchase
How to Extract Meta tags of a Web site On a Button Click

Author: DevASP
Download Source Code : 329_extract_meta_tag_csharp1.zip

In this simple you learn to extract meta tags of a site without open that site and a site’s meta tags have information about that site. This is very easy in the Visual Studio.net.

To do this there are some simple steps. First create a web application then create some controls with these properties.

<asp:HyperLink id="HyperLink18" style="Z-INDEX: 106; LEFT: 272px; POSITION: absolute; TOP: 40px" runat="server" Font-Size="Large" ForeColor="#404040" Font-Names="Arial" Font-Bold="True">Meta-tags Extractor</asp:HyperLink>

<asp:Button id="Button2" style="Z-INDEX: 107; LEFT: 584px; POSITION: absolute; TOP: 136px" runat="server" Text="Clear" Width="64px" />

<asp:Label id="Label9" style="Z-INDEX: 100; LEFT: 72px; POSITION: absolute; TOP: 136px" runat="server" Font-Names="Arial">Extract meta-tags from: </asp:Label>

<asp:TextBox id="txtdomain" style="Z-INDEX: 104; LEFT: 288px; POSITION: absolute; TOP: 136px" runat="server" Width="192px">http://devasp.com</asp:TextBox>

<asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 504px; POSITION: absolute; TOP: 136px" runat="server" Text="Extract!" />

<asp:TextBox id="txtresult" style="Z-INDEX: 105; LEFT: 72px; POSITION: absolute; TOP: 192px" runat="server" Width="632px" Height="370px" TextMode="MultiLine" />

  • After that all just write code on button clike event of Button1

string uri=this.txtdomain.Text ;

System.Uri weburi = new System.Uri(uri,false);

System.Text.StringBuilder sbuild=new System.Text.StringBuilder();

string temp="";

int a=0,temp1=0,cou=0,check_2=0;

string b=" ",c;

c="";

try

{

System.Net.HttpWebRequest webrequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(weburi);

System.Net.HttpWebResponse webresponse=(System.Net.HttpWebResponse) webrequest.GetResponse();

System.IO.StreamReader webstream = new System.IO.StreamReader(webresponse.GetResponseStream (),System.Text.Encoding.ASCII );

while((temp=webstream.ReadLine())!= null)

{

temp = temp.Trim('\r');

temp = temp.Trim('\n');

temp = temp.Trim('\r');

b+=temp;

}

{

a=b.IndexOf("

if(a>-1)

{

check_2=b.IndexOf(">",a+1);

temp1=check_2+1;

check_2=check_2-a;

check_2+=1;

c=b.Substring(a,check_2);

cou+=1;

while(temp1

{

a=b.IndexOf("

if(a>0)

{

check_2=b.IndexOf(">",a+1);

temp1=check_2+1;

check_2=check_2-a;

check_2+=1;

c+=b.Substring(a,check_2);

cou+=1;

}

else

break;

}

}

txtresult.Text=c;

}

txtresult.Text+= "\r\n";

txtresult.Text+= cou;

webstream.Close();

}

catch(System.Net.WebException wex)

{

Response.Write (wex.Message );

}

  • After that write this code on button click event of button2

txtresult.Text="";

This is the complete code for this purpose; a very simple and useful techinque.

 

Article Comments
this article is very OK thanks for doing it!!

Posted on 11/11/2006 11:31:39 AM by sadiel

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to Create Mobile Web Application in ASP.Net 2.0

Disclaimer - Privacy
© 2002-2012 DevASP.net