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());


Comments