Reputation:
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
Upvotes: 1
Views: 6352
Reputation: 67175
When working with ASP.NET, it's necessary to clarify if you are talking about an ASP.NET sitemap (used for site navigation), and a search-engine sitemap.
If you are referring to a search-engine sitemap, check out the article at http://www.blackbeltcoder.com/Articles/asp/dynamic-sitemaps-in-asp-net. It presents code for doing what you want.
Upvotes: 0
Reputation: 119
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"));
Upvotes: 5
Reputation: 1979
Maybe mine? :)
Some example of usage and download file you can find here. Look for SiteMap Generator section.
Upvotes: 2
Reputation: 228
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).
Upvotes: 1