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:
- try
- {
- string cs = ConfigurationManager.ConnectionStrings[" write here your connection string name"].ConnectionString;
- cn = new SqlConnection(cs);
- string mydomain = "http://www.shrilekha.com"; // Write here your domain
- string strSql = " write here your sql query example: Select * from businessTable";
- SqlDataAdapter dacontent = new SqlDataAdapter(strSql, cn);
- DataSet dscontent = new DataSet();
- dacontent.Fill(dscontent, "SiteMap");
- XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
- writer.WriteStartDocument();
- writer.WriteStartElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");
- writer.WriteStartElement("url");
- writer.WriteElementString("loc", "http://www.shrilekha.com");
- writer.WriteElementString("priority", "0.5");
- writer.WriteEndElement();
- if (dscontent.Tables[0].Rows.Count > 0)
- {
- DataRow dtr;
- int i = 0;
- while (i < dscontent.Tables[0].Rows.Count)
- {
- dtr = dscontent.Tables[0].Rows[i];
- writer.WriteStartElement("url");
- string bname = dtr["BusinessName"].ToString().Replace(" ","-").Replace("&","and").Replace(".","");
- writer.WriteElementString("loc", mydomain +"/"+ bname.ToString());
- writer.WriteElementString("priority", "0.5");
- writer.WriteEndElement();
- i++;
- }
- }
- writer.WriteEndDocument();
- writer.Close();
- }
- catch (Exception ex)
- {
- }
Run The project end enjoy.
https://haryanapolice-gov.in/
ReplyDeletehttps://haryanapolice-gov.in/
https://haryanapolice-gov.in/hssc-police-constable-admit-card-roll-number/
How To Create Xml Sitemap Dynamically In Asp.Net - Asp Tanmoy >>>>> Download Now
Delete>>>>> 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
Haryana Police Recruitment 2018
ReplyDeleteHaryana Police Vacancy 2018 Notification
Haryana Police Admit Card
How To Create Xml Sitemap Dynamically In Asp.Net - Asp Tanmoy >>>>> Download Now
ReplyDelete>>>>> 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