aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Get Title and Description of URL in Like Facebook

May 13, 2013

Here I will explain how to get title & meta description of url in using C# and VB.NET or get page title and description from page url in using HTMLAgilityPack in C# and VB.NET.


To get title & description of url we need to write the following code in aspx page

<html xmlns="">
<title>Get Title and Meta Description from Live URL</title>
<form id="form1" runat="server">
<h3>Get Title and Meta Description from Live URL</h3>
<b>Enter Url:</b>
<asp:TextBox ID="txtURL" runat="server" AutoPostBack="True" ontextchanged="txtURL_TextChanged" Width="250px"></asp:TextBox>
<asp:TextBox ID="txtTiltle" runat="server" Width="250px"></asp:TextBox>
<td valign="top">
<asp:TextBox ID="txtDesc" runat="server" Rows="7" Columns="40" TextMode="MultiLine"></asp:TextBox>
Now in code behind add the following namespaces

C# Code

using System;
using System.Net;
using System.Text.RegularExpressions;
using HtmlAgilityPack;
Here I added new HtmlAgilityPack namespace by using this reference we can parse out HTML pages you can get this dll reference from attached sample folder or from this url

Now add below code in code behind

protected void txtURL_TextChanged(object sender, EventArgs e)
String url = txtURL.Text;
//Get Title
WebClient x = new WebClient();
string source = x.DownloadString(url);
txtTiltle.Text = Regex.Match(source, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"].Value;
//Method to get Meta Tags
private void GetMetaTagValues(string url)
//Get Meta Tags
var webGet = new HtmlWeb();
var document = webGet.Load(url);

var metaTags = document.DocumentNode.SelectNodes("//meta");

if (metaTags != null)
foreach (var tag in metaTags)
if (tag.Attributes["name"] != null && tag.Attributes["content"] != null && tag.Attributes["name"].Value == "description")
txtDesc.Text = tag.Attributes["content"].Value;

Imports System.Net
Imports System.Text.RegularExpressions
Imports HtmlAgilityPack
Partial Class VBCode
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs)
End Sub
Protected Sub txtURL_TextChanged(sender As Object, e As EventArgs)
Dim url As [String] = txtURL.Text
'Get Title
Dim x As New WebClient()
Dim source As String = x.DownloadString(url)
txtTiltle.Text = Regex.Match(source, "\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups("Title").Value
'Method to get Meta Tags
End Sub
Private Sub GetMetaTagValues(url As String)
'Get Meta Tags
Dim webGet = New HtmlWeb()
Dim document = webGet.Load(url)
Dim metaTags = document.DocumentNode.SelectNodes("//meta")
Dim tag
If metaTags IsNot Nothing Then
For Each tag In metaTags
If tag.Attributes("name") IsNot Nothing AndAlso tag.Attributes("content") IsNot Nothing AndAlso tag.Attributes("name").Value = "description" Then
txtDesc.Text = tag.Attributes("content").Value
End If
End If
End Sub
End Class

Download Sample Code Attached

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Anonymous said...


Unknown said...

System.IO.FileNotFoundException: Could not find 1. file 'C:\WINDOWS\system32\'.

2. System.Net.WebException: The remote name could not be resolved:

How to Resolve these errors....


DotNet Kings said...

for this HtmlAgilityPack; namespace which files dll need to be added. i downloaded from codeplex it has so many folder are available. In which dll i need to include..



Dhiraj said...

Hii Sir. Suresh I am Dhiraj a Student of class XI.I want to make my own website in .net and i found your website as the best website on Internet for learners.
Sir, Can you post a new article, in that "a user can post his questions and at bottom a button to comment on that considering the user is logged in or not if not then login using fb."

Robert said...

This was a really great contest and hopefully I can attend the next one. It was alot of fun and I really enjoyed myself..
buy real fb likes

Anonymous said...

google not allowimg meta tags any more ! how to get description now ??

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.