views:

548

answers:

5

Is there a lib i can use in C# to generate a sitemap for my asp.net website?

I am looking for something that i can insert data into and it will tell me if the generated sitemap has reach its limit or if the file size has reach it limit. Then allows me to save it as a file

+2  A: 

Do you mean the SiteMap Class?

SiteMap Class

Joshua Drake
+1. I looked at the example and it looks weird. It seems like i need to write an XML version by hand? and i use sitemap to read from it? Is that what it does? I am looking for something that i can insert data into and it will tell me if the generated sitemap has reach its limit (i think it was 5k) or if the size reach it limit. Then allows me to save it as an XML sitemap.
acidzombie24
+1  A: 

AFAIK theres no libs for what you want to do (judging by your comments). You can however use .net xml wrapped into your own class to generate it. Its shouldnt be difficult. You also should take account of ascii characters and 4 byte breaks (2 for \r and 2 for \n).

+1  A: 

Maybe mine? :)

Some example of usage and download file you can find here. Look for SiteMap Generator section.

dario-g
Excellent. I dont see any if statements and i check wikipedia quickly. Will this tell me i hit the 50k limit? Or if the file generated size (after escaping characters and all that) has hit the limit (ignoring the last entry i guess)?
acidzombie24
ahh, no source, its a dll. so i can fix anything if i need to ;). It doesnt look like it tells me when i hit the limit (50k entries/10mb).
acidzombie24
No, it has no limit but 10Mb is enough for common sites.
dario-g
You know what, i'll use it. I looked into it and checking the filesize seems more effort then its worth. Your thing doesnt automatically count? i'll just write a counter with it and exist when i hit the 50k. I just hope i dont go over the limit (or forget about the code once i have enough to hit 50k)
acidzombie24
A: 

You can also check this out. It includes the source code and a simple example.

The API is very easy to use.

It looks weak. Also i dont want to crawl but to generate. I think i'll need to write my own and put 1000 urls per file and use many sitemaps with the sitemapindex. After reading the specs again i hope i can only need to touch the last 1000 urls (i forget what error code i should use when something use to exist but doesnt. It wasnt 404).
acidzombie24
A: 

Here you can check my code to generate Sitemap.xml based on already prepared collection of SiteMapUrl objects:

            XNamespace ns = XNamespace.Get("http://www.sitemaps.org/schemas/sitemap/0.9");
        XElement urlset = null;
        XDocument siteMapDocument = new XDocument(urlset = new XElement(ns + "urlset"));
        foreach (var links in siteMap.SiteMapUrls)
        {
            urlset.Add(new XElement
            (ns + "url",
            new XElement(ns + "loc",links.Location),
            new XElement(ns + "lastmod", DateTime.Now),
            new XElement(ns + "changefreq", Enum.GetName(typeof(SiteMapUrlChangeFreqs), links.ChangeFreq)),
            new XElement(ns + "priority", "0.2")
            ));
        }

        siteMapDocument.Save(String.Format("{0}\\{1}",AppDomain.CurrentDomain.BaseDirectory,"SiteMap.xml"));
maciejgren