Web developers wiki ASP.NET Sitecore Sharepoint Kentico by Evident Interactive

Sitecore sitemap SEO

Modified: 2008/11/19 09:51 by arjan - Categorized as: Csharp, Sitecore


This piece of code generates a simple sitemap for search engine, according to the standard of http://sitemaps.org

Framework 3.5 is required as it uses LINQ.

C#:
<Page Language="C#" AutoEventWireup="true" Inherits="System.Web.UI.Page" %>
< script runat="server" type="text/C#">

protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "application/xml";

XNamespace xmlns = "http://www.sitemaps.org/schemas/sitemap/0.9"; XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";

XElement root = new XElement(xmlns + "urlset", new XAttribute(XNamespace.Xmlns + "xsi", xsi), new XAttribute(xsi + "schemaLocation", xmlns), from Sitecore.Data.Items.Item item in Sitecore.Context.Database.SelectItems("/sitecore/content/home//*") select new XElement(xmlns + "url", new XElement(xmlns + "loc", Sitecore.Web.WebUtil.GetFullUrl(item.Paths.GetFriendlyUrl("/sitecore/content/home/", ""))) ) );

root.Save(new System.IO.StreamWriter(Response.OutputStream, System.Text.UTF8Encoding.UTF8), SaveOptions.DisableFormatting); }

</script>

 © Evident Interactive BV