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.

Get Site Title and Meta Tag Information through URL

Viewed:  1405 
Posted On:  03/02/2015 01:00:50 
How we can know about a site through it's URL only in c# 

In this article I am going to explain how we can get title and meta tag information of a web site through its URL.

For this I need to add HtmlAgilityPack reference.

So right click on your application solution explorer and select Manage NuGet Packages:


Image 1.

You can also download this dll from below link:


Image 2.

Now my aspx is:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="URLInformation.Default" %>
<!DOCTYPE html>
<html xmlns="">
<head runat="server">
    <title>Get Website Information through URL</title>
    <form id="form1" runat="server">
            <table style="border: solid 15px blue; padding: 7px; width: 100%;">
                    <td style="background-color: green; color: white; text-align: center;" colspan="2">
                        <h3>Get Title and Description of a Web Site</h3>
                <tr style="background-color: skyblue;">
                    <td style="vertical-align: top; padding: 10px;">Type URL:
                    <td style="padding: 10px;">
                        <asp:TextBox ID="txtURL" runat="server" AutoPostBack="True" Width="450px"></asp:TextBox>
                        <br />
                        <br />
                        <asp:Button ID="btnGetInfo" runat="server" Text="Get Information" OnClick="btnGetInfo_Click" />
                <tr style="background-color: orange;">
                    <td style="padding: 10px;">Title:
                    <td style="padding: 10px;">
                        <asp:TextBox ID="txtTiltle" runat="server" Width="450px"></asp:TextBox>
                <tr style="background-color: orange;">
                    <td style="padding: 10px;">Description:
                    <td style="padding: 10px;">
                        <asp:TextBox ID="txtMetaTagDesc" runat="server" Width="450px" Height="70px" TextMode="MultiLine"></asp:TextBox>

My aspx.cs code 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.Text.RegularExpressions;
using HtmlAgilityPack;
namespace URLInformation
    public partial class Default : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
        protected void btnGetInfo_Click(object sender, EventArgs e)
            String _url = txtURL.Text;
            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;
        private void GetURLMetaTag(string url)
            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")
                        txtMetaTagDesc.Text = tag.Attributes["content"].Value;
                txtMetaTagDesc.Text = "";


Now run the application:


Image 3.


Image 4.


Image 5.

By dotnet  On  06/04/2016 01:35:37

What is NuGet Package Manager
Convert Post Title Into UrL
         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us