As I said in a previous post, here's the code for generating a sitemap. Enjoy.
SiteMapGenerator.cs
using System;
using Snowball.Common;
using System.IO;
namespace Snowball.Web
{
///
/// Generates a sitemap for dotnetnuke.
///
class SiteMapGenerator
{
///
/// Generates a site map for a dotnetnuke 2.1.2 website.
///
[STAThread]
static void Main(string[] args)
{
string portals=Settings.GetSetting("Portals");
string[] portalList=portals.Split(new char[]{','});
string htmlFilename=Settings.GetSetting("HtmlFileName");
string xmlFilename=Settings.GetSetting("XmlFileName");
string googleFilename=Settings.GetSetting("GoogleSiteMapFileName");
for (int i=0;i < portalList.Length;i++)
{
string[] portalData=portalList[i].Split(new char[]{'|'});
int portalId=Convert.ToInt32(portalData[0]);
string baseUrl=portalData[1];
string outputDir=portalData[2];
if (!outputDir.EndsWith(@"\"))
{
outputDir+=@"\";
}
TabList list=TabList.GetTabs(portalId,baseUrl);
using (StreamWriter writer=new StreamWriter(outputDir + xmlFilename))
{
writer.Write(list.ToXml());
}
using (StreamWriter writer=new StreamWriter(outputDir + googleFilename))
{
writer.Write(list.ToGoogleSitemap());
}
using (StreamWriter writer=new StreamWriter(outputDir + htmlFilename))
{
writer.Write(list.ToString());
}
}
}
}
}
Tab.cs
using System;
using System.Data;
using Microsoft.ApplicationBlocks.Data;
using Snowball.Common;
using log4net;
using System.Text;
using System.Collections;
namespace Snowball.Web
{
///
/// Represents a single dotnetnuke tab.
///
internal class Tab
{
private TabList m_childTabs=new TabList();
private bool m_hasChildren=false;
private Uri m_url=null;
private string m_anchor;
private string m_description;
private int m_id=-1;
private int m_parentId=-1;
private int m_tabOrder=-1;
private int m_level=-1;
private bool m_isVisible=false;
private bool m_disabled=false;
private bool m_deleted=false;
private bool m_adminTab=false;
private string m_defaultPage=string.Empty;
private string m_defaultHost="http://www.mysite.com/";
private static DataSet m_rewriterDirectories=null;
private static SortedList m_dirs=null;
private static string m_dnnCs=Settings.GetSetting("DotNetNukeConnectionString");
private static string m_snowballCs=Settings.GetSetting("SnowballConnectionString");
///
/// Default Constructor.
///
public Tab()
{
}
///
/// Allow creation of tab with specified portal id and default host.
///
/// The portal id for this tab.
/// The default host for this tab.
public Tab(int portalId, string defaultHost)
{
if (!defaultHost.EndsWith("/"))
{
defaultHost+="/";
}
m_defaultHost=defaultHost;
m_childTabs.DefaultHost=defaultHost;
m_childTabs.PortalId=portalId;
}
///
/// Allows creation of a specific tab.
///
/// The id of the tab to create.
/// The portal id of the tab.
/// the default host of this tab.
public Tab(int id,int portalId,string defaultHost):this(portalId,defaultHost)
{
LoadTab(id);
}
///
/// Allows for the creation of a tab from a datarow.
///
/// The data row containing the tab data.
/// The portal of this tab.
/// The host of this tab.
public Tab(DataRow row,int portalId,string defaultHost):this(portalId,defaultHost)
{
LoadTab(row);
}
///
/// Gets or sets child tabs of this tab.
///
public TabList ChildTabs
{
get
{
return m_childTabs;
}
set
{
m_childTabs=value;
}
}
///
/// Gets or sets whether or not this tab has children.
///
public bool HasChildren
{
get
{
return m_hasChildren;
}
set
{
m_hasChildren=value;
}
}
///
/// Gets the URI for this tab.
///
public Uri Url
{
get
{
return m_url;
}
}
///
/// Gets the tab description--note that this is the title of the tab.
///
public string Description
{
get
{
return m_description;
}
}
///
/// Gets an anchor (A) tag for html.
///
public string Anchor
{
get
{
return "this.Url.ToString() + "\">" + this.Description + "";
}
}
///
/// Gets the id of this tab.
///
public int Id
{
get
{
return m_id;
}
}
///
/// Gets the parent Id of this tab.
///
public int ParentId
{
get
{
return m_parentId;
}
}
///
/// Gets the Tab Order for this tab.
///
public int TabOrder
{
get
{
return m_tabOrder;
}
}
///
/// Gets this tab's level.
///
public int Level
{
get
{
return m_level;
}
}
///
/// Gets whether or not this tab is visible.
///
public bool Visible
{
get
{
return m_isVisible;
}
}
///
/// Gets whether or not this tab is disabled.
///
public bool Disabled
{
get
{
return m_disabled;
}
}
///
/// Gets whether or not this tab has been deleted.
///
public bool Deleted
{
get
{
return m_deleted;
}
}
///
/// Gets or sets whether this tab is the admin tab or not.
///
public bool AdminTab
{
get
{
return m_adminTab;
}
set
{
m_adminTab=value;
}
}
///
/// Loads a tab from a datarow.
///
/// The row containing the data for this tab.
private void LoadTab(DataRow row)
{
SetValue(row["Title"],ref m_description);
m_url=SetUri((int) row["TabId"]);
m_anchor="" + m_description + "";
SetValue(row["IsDeleted"],ref m_deleted);
SetValue(row["DisableLink"],ref m_disabled);
SetValue(row["HasChildren"],ref m_hasChildren);
SetValue(row["TabId"],ref m_id);
SetValue(row["IsVisible"],ref m_isVisible);
SetValue(row["Level"],ref m_level);
SetValue(row["ParentId"],ref m_parentId);
SetValue(row["TabOrder"],ref m_tabOrder);
}
///
/// Sets a value if the value is not DBNull.Value.
///
/// The value to check for DBNull
/// The ref obejct variable to set if the value is not dbnull.
private void SetValue(object value, ref object variable)
{
if (value != DBNull.Value)
{
variable=value;
}
}
///
/// Sets a value if the value is not DBNull.Value.
///
/// The value to check for DBNull
/// The ref obejct variable to set if the value is not dbnull.
private void SetValue(object value, ref string variable)
{
object result=null;
SetValue(value,ref result);
if (result != null)
{
variable=Convert.ToString(result);
}
}
///
/// Sets a value if the value is not DBNull.Value.
///
/// The value to check for DBNull
/// The ref obejct variable to set if the value is not dbnull.
private void SetValue(object value, ref int variable)
{
object result=null;
SetValue(value,ref result);
if (result != null)
{
variable=Convert.ToInt32(result);