Okay...when I get some free time (which equates to some slow time), I'm going to write a full featured application which can generate a sitemap path by being pointed to the root folder and using some lexical analysis to identify which page is above what, etc....but for now, I needed something which (in a pure, raw fashion), just generated the XML tags for me so I could move them about freely when constructing a sitemap path, the source for my endeavor is below (it works for me, again, if it doesn't work for you - you're on your own!). The XML generated was well formatted for me (IE didn't complain when I opened it up inside it).
using System;
using System.Collections.Generic;
using System.Text;
namespace SiteMapGenericBuilder
{
class Program
{
private static System.String root = "";
static void Recurse(System.IO.DirectoryInfo cur, System.Xml.XmlTextWriter tw)
{
foreach (System.IO.FileInfo fi in cur.GetFiles())
{
if (fi.Extension == ".aspx")
{
System.String webPath = "~" + fi.FullName.Replace(root, "").Replace("\\", "/");
tw.WriteStartElement("siteMapNode");
tw.WriteAttributeString("url", webPath);
tw.WriteAttributeString("title", "");
tw.WriteAttributeString("description", "");
tw.WriteFullEndElement();
}
}
foreach (System.IO.DirectoryInfo di in cur.GetDirectories())
Recurse(di,tw);
}
static void Main(string[] args)
{
// this app should be placed in the root of the web application
// (alongside the web.config file).
System.IO.DirectoryInfo di =
new System.IO.DirectoryInfo(System.IO.Directory.GetCurrentDirectory());
if (System.IO.File.Exists(di.FullName + "/web.config"))
{
root = di.Parent.FullName;
System.IO.FileStream fs = new System.IO.FileStream("web.sitemap.part",
System.IO.FileMode.Create);
System.IO.StreamWriter sw = new System.IO.StreamWriter(fs);
System.Xml.XmlTextWriter tw = new System.Xml.XmlTextWriter(sw);
tw.Formatting = System.Xml.Formatting.Indented;
// recurse over all the directories.
tw.WriteStartDocument();
tw.WriteStartElement("partial_sitemap");
Recurse(di, tw);
tw.WriteEndElement();
tw.WriteEndDocument();
tw.Flush();
tw.Close();
}
}
}
}