Click here to Skip to main content
12,559,389 members (49,405 online)
Click here to Skip to main content
Add your own
alternative version


19 bookmarked

C# Google Sitemap Class

, 29 Nov 2006
Rate this:
Please Sign up or sign in to vote.
An article that describes a C# class to simplify Google Sitemap file generation.

csharp sitemap class


Sitemaps are an easy way for web masters to inform search engines about pages on their website that needs to be crawled. It is an XML file which consists of lists of URLs with additional meta data on each URL. Sitemaps is arguably one of the most important feature of Site SEO (Search Engine Optimization). With the release of sitemap protocol 0.90, Google has managed to gain support for two other search giants, namely Microsoft and Yahoo!, to use the standard protocol. This module allows you to easily create and modify sitemaps generation for your website.

The C# Sitemap Class

To use the C# sitemap class, all you have to do is to include two .cs files in your project, namely, Sitemap.cs and Url.cs. Url.cs consists of the basic element for individual URL needed in the sitemap. Sitemap.cs is the class that will be generating the sitemap XML file.

Using the Code

First, you'll have to create a Url object. A Url object has four properties:

  • Loc
  • ChangeFreq
  • Priority
  • LastModified

Examples are as below:

url url1 = new url();
url1.loc = "";
url1.priority = "1";
url1.lastmodifieddatetime =;
url1.changefreq = "always";

You'll then need to create the Sitemap object and use the public Add method, adding the url1 object you have created. However, remember to put the intended file name as the parameter to the sitemap class constructor. Example:

Sitemap sitemap0 = new Sitemap(txtFilename.Text);

and in order to add a new URL:

Url url2 = new Url();
url2.Loc = "";
url2.Priority = "0.8";
url2.LastModifiedDateTime = DateTime.Now;
url1.ChangeFreq = "always";


After adding all the URLs, call the Write method, and the sitemap file will be generated.



  • Rev 0.1 - 11/29/2006 -- Initial revision.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Singapore Singapore
Daytime Electronic/RF Engineer and night time coder. He sometime rant about technology and other stuff on his personnel blog

His latest hobby project is building Job Search Engine

You may also be interested in...

Comments and Discussions

GeneralAlternative Class Pin
ekul246-Oct-10 19:39
memberekul246-Oct-10 19:39 
Generalok Pin
ngc.vn22-Jun-08 0:50
memberngc.vn22-Jun-08 0:50 
GeneralIt's imposible Pin
Member #358862110-Feb-07 6:20
memberMember #358862110-Feb-07 6:20 
GeneralRe: It's imposible Pin
greenrob10-Feb-07 6:33
membergreenrob10-Feb-07 6:33 
GeneralHonestly Pin
Jan R Hansen4-Dec-06 2:45
memberJan R Hansen4-Dec-06 2:45 
GeneralRe: Honestly Pin
greenrob9-Dec-06 9:14
membergreenrob9-Dec-06 9:14 
GeneralBasically... Pin
Itay Sagui29-Nov-06 5:14
memberItay Sagui29-Nov-06 5:14 
GeneralRe: Basically... Pin
teongkee29-Nov-06 14:16
memberteongkee29-Nov-06 14:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161026.1 | Last Updated 29 Nov 2006
Article Copyright 2006 by teongkee
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid