1: private void SortWebTemplates(SPWeb web, bool recursive, uint lcid)
2: {
3: SPWebTemplateCollection webTemplates = web.GetAvailableWebTemplates(lcid);
4: StringBuilder sb = new StringBuilder();
5:
6: Collection<SPWebTemplate> collection = new Collection<SPWebTemplate>();
7: foreach (SPWebTemplate template in webTemplates)
8: {
9: bool itemAdded = false;
10:
11: for (int i = 0; i < collection.Count; i++)
12: {
13: if (template.Title.CompareTo(collection[i].Title) < 0)
14: {
15: collection.Insert(i, template);
16: itemAdded = true;
17: break;
18: }
19: }
20:
21: if (!itemAdded)
22: collection.Add(template);
23: }
24:
25: sb.Append("<webtemplates><lcid id=\"all\">");
26: foreach (SPWebTemplate webTemplate in collection)
27: {
28: sb.Append("<webtemplate name=\"" + webTemplate.Name + "\" />");
29: }
30: sb.Append("</lcid><lcid id=\"" + lcid.ToString() + "\">");
31: foreach (SPWebTemplate webTemplate in collection)
32: {
33: sb.Append("<webtemplate name=\"" + webTemplate.Name + "\" />");
34: }
35: sb.Append("</lcid></webtemplates>");
36:
37: web.AllProperties["__WebTemplates"] = sb.ToString();
38: web.Update();
39:
40: if (recursive && web.Webs.Count > 0)
41: {
42: foreach (SPWeb subWeb in web.Webs)
43: {
44: SortWebTemplates(subWeb, recursive, lcid);
45: subWeb.Dispose();
46: }
47: }
48: }