Returning Site Directory SPList

SharePoint + SharePoint Development Owner todayDecember 2, 2018 2 3

share close

Often times it is required to get a reference to the SPList that contains the site directory information, this is an important task when you are considering construction of navigation solutions or when building holistic reporting tools in order to support governance of site sprawl (which is easy to have happen, but sure is a PITA to get cleaned up!). In order to do this, you will use the Microsoft.SharePoint.SPListTemplateType enumeration to specify the type of a list definition or a list template, in this case the value 300 leveraging a direct cast. For example, a simple method to hydrate the coordinating SPList object can be done as such:

public static SPList ReturnPortalSiteList(SPWeb web)
return web.Lists.Cast().FirstOrDefault(list => Equals(list.BaseTemplate, (SPListTemplateType) 300));
Easy as pie! 🙂

Written by: Owner

Tagged as: .

Rate it

Previous post