Here is some code to sort a collection of sites by title.
Create a custom IComparer for sites:
public class SPListItemComparer : IComparer
{
#region IComparer Members
public int Compare(object x, object y)
{
if (!(x is SPListItem) || !(y is SPListItem))
throw new ArgumentException("Cannot compare non-SPListItem objects using SPListItemComparer");
return string.Compare(((SPListItem)x).Name, ((SPListItem)y).Name);
}
#endregion
}
Then, put the sites into a sortable collection such as ArrayList and call the collection's Sort method using your custom IComparer.
SPWebCollection collWebsite = oSiteCollection.AllWebs;
ArrayList sortedWebs = new ArrayList(collWebsite.Count);
foreach (SPWeb oWebsite in collWebsite)
{
sortedWebs.Add(oWebsite);
}
sortedWebs.Sort(new ArrowUtils.SPWebSortComparer());


I am using Sharepoint 2007.
Using the following method, I am trying to sort SPWebCollection accordind to created date. How to get ArrowUtils class?
SPWeb web = SPContext.Current.Web;
SPWebCollection collWebsite = web.GetSubwebsForCurrentUser();
Posted by: Sharepoint | 02/17/2011 at 02:22 PM
ArrowUtils is my class where I created SPWebSortComparer.
What you want to do is create an SPWebSortComparer, but instead of using their names, use their created date in the Compare method.
Posted by: meowkins | 02/17/2011 at 05:17 PM