Enumerating All SPWebs In SPFarm.Local Into Strongly Typed Collection
So when enumerating the SPWebs within a SPFarm to build a strongly typed SPWeb collection for whatever purpose your enumeration might look like this:
- public static List<SPWeb> WebsPreppedForIteration()
- {
- var collection = new List<SPWeb>();
- foreach (SPSite x in SPFarm.Local.Services.OfType<SPWebService>().SelectMany
- (svc => ((svc).WebApplications.Where
- (webApp => !webApp.Properties.ContainsKey("Microsoft.Office.Server.SharedResourceProvider")).SelectMany
- (webApp => webApp.Sites.Cast<SPSite>()))).Where
- (x => !Equals(x.RootWeb.Title, "Central Administration")))
- {
- collection.AddRange(x.RootWeb.Webs.Cast<SPWeb>());
- }
- return collection;
- }
I saw this in a code review today. The part I am wondering about is the SPWebApplication property bag to query the key for WCAM as opposed to do a clunky string SPWeb.Title comparison. Putting the keys out to standard output hasn’t yielded anything particularly evident, and I’m getting frustrated with the under-the-hood, unnecessary foreach loop with a fancy shirt on (the second LINQ query against the Title property(,
Does anyone know the key for WCAM?
One Comment
Trackbacks/Pingbacks
- Links (10/21/2010) « Everything SharePoint/Silverlight - [...] Enumerating All SPWebs In SPFarm.Local Into Strongly Typed Collection [...]
- Links a lot, Sharepoint, Chartcontroll,xpath, SP Client Object Model « Just tinkering Blog - [...] Enumerating All SPWebs In SPFarm.Local Into Strongly Typed Collection [...]
Articles & Research
SharePoint Security
SharePoint Development
SharePoint Architecture
Claims Authentication
Forefront For SharePoint
AIS / Dynamics GP
Team Foundation Server
Pex And Moles
ISA/TMG/IAG/UAG
DPM
Cardspace
Research Methodology
Rural ICT Development
Numerical Analysis
Multi-Level Research
Knowledge Management
Personal/Off-Topic
Twitter Comment
So when enumerating the SPWebs within a SPFarm to build a strongly typed SPWeb collection … [link to post] #strongly
– Posted using Chat Catcher