How to create XML SiteMap Dynamically in ASP.Net - ASP TANMOY

Latest

Friday 16 February 2018

How to create XML SiteMap Dynamically in ASP.Net



Today I am going to explain how to create XML SiteMap dynamically. I am using Visual Studio 2012 and MS SQL Database. For a large website, you cannot use any tool to create XML Sitemap by Accessing Database. So the best way to create a program to create XML SiteMap. Please follow my below code.

Namespace:

using System.Xml;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

Step1:
Create a website by opening the visual studio.I have named it as sitemap.aspx

Step2: 

Remove all lines from the aspx page and Paste the below line.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="sitemap.aspx.cs" Inherits="WebApplication1.sitemap" ContentType ="text/xml" %>


Step 3: 

Double click on the aspx page and add all namespace written above.

Step 4:

Write the below code on page load event

Code:
  1. try
  2.             {
  3.                 string cs = ConfigurationManager.ConnectionStrings[" write here your connection string name"].ConnectionString;
  4.                 cn = new SqlConnection(cs);
  5.                 string mydomain = "http://www.shrilekha.com"; // Write here your domain

  6.                 string strSql = " write here your sql query example: Select * from businessTable";
  7.                 SqlDataAdapter dacontent = new SqlDataAdapter(strSql, cn);
  8.                 DataSet dscontent = new DataSet();
  9.                 dacontent.Fill(dscontent, "SiteMap"); 

  10.                 XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
  11.                 writer.WriteStartDocument();
  12.                 writer.WriteStartElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");

  13.                 writer.WriteStartElement("url");

  14.                 writer.WriteElementString("loc", "http://www.shrilekha.com");
  15.                 writer.WriteElementString("priority", "0.5");
  16.                 writer.WriteEndElement();

  17.                 
  18.                 if (dscontent.Tables[0].Rows.Count > 0)
  19.                 {
  20.                     DataRow dtr;
  21.                     int i = 0;
  22.                     while (i < dscontent.Tables[0].Rows.Count)
  23.                     {
  24.                         dtr = dscontent.Tables[0].Rows[i];

  25.                         
  26.                         writer.WriteStartElement("url");

  27.                        
  28.                         string bname = dtr["BusinessName"].ToString().Replace(" ","-").Replace("&","and").Replace(".","");


  29.                         writer.WriteElementString("loc", mydomain +"/"+ bname.ToString());
  30.                         writer.WriteElementString("priority", "0.5");

  31.                         
  32.                         writer.WriteEndElement();


  33.                         i++;
  34.                     }
  35.                 }
  36.                 writer.WriteEndDocument();
  37.                 writer.Close();

  38.             }
  39.             catch (Exception ex)
  40.             {

  41.             }
Step: 5:
Run The project end enjoy.


4 comments:

  1. https://haryanapolice-gov.in/
    https://haryanapolice-gov.in/
    https://haryanapolice-gov.in/hssc-police-constable-admit-card-roll-number/

    ReplyDelete
    Replies
    1. How To Create Xml Sitemap Dynamically In Asp.Net - Asp Tanmoy >>>>> Download Now

      >>>>> Download Full

      How To Create Xml Sitemap Dynamically In Asp.Net - Asp Tanmoy >>>>> Download LINK

      >>>>> Download Now

      How To Create Xml Sitemap Dynamically In Asp.Net - Asp Tanmoy >>>>> Download Full

      >>>>> Download LINK Ic

      Delete
  2. How To Create Xml Sitemap Dynamically In Asp.Net - Asp Tanmoy >>>>> Download Now

    >>>>> Download Full

    How To Create Xml Sitemap Dynamically In Asp.Net - Asp Tanmoy >>>>> Download LINK

    >>>>> Download Now

    How To Create Xml Sitemap Dynamically In Asp.Net - Asp Tanmoy >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete