Thursday, December 17, 2009

Code to Create Sites List in SharePoint

Created Sites List

Last but not least, create a list that contains all sites that were created with your site provision. This list will be useful to monitor exiting sites and most importantly you could execute CAML queries to retrieve sites from the list.

For example, if you want to display the last five sites that were created. You can do it simply by using this CAML query:
SPListItemCollection itemColl = null; 
using (SPSite site = new SPSite (SPContext.Current.Site.Url)) 
   using (SPWeb web = site.OpenWeb ()) 
     SPList list = web.Lists [“CreatedSitesList”];  
     SPQuery qry = new SPQuery(); 
     qry.Query = ""; 
     qry.ViewFields = ""; 
     qry.RowLimit = 5; 
     itemColl = list.GetItems(qry); 

No comments:

Post a Comment