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()
-
{
-
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?
Related posts:
- Typed Dictionary With SharePoint Web Titles And Typed SPListItem Collection
- Solving SharePoint FullTextSqlQuery Wrong Site Collection Error
- Return Current User SharePoint MySite URL
- Strongly Typed SharePoint List Collections By Template Type
- IT Consulting Ethics – Part 3 – Benefit-Cost Analysis and Government Considerations
3 Comments »
RSS feed for comments on this post. TrackBack URL























Articles & Research
SharePoint Architecture
Research Methodology
Personal/Off-Topic
Article Or Research Filed Under 

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
Comment by blogsoftheworld (blogs of the world) — August 8, 2010 @ 3:03 pm
[...] Enumerating All SPWebs In SPFarm.Local Into Strongly Typed Collection [...]
Pingback by Links (10/21/2010 « Everything SharePoint/Silverlight) — October 21, 2010 @ 7:57 am
[...] Enumerating All SPWebs In SPFarm.Local Into Strongly Typed Collection [...]
Pingback by Links a lot, Sharepoint, Chartcontroll,xpath, SP Client Object Model « Just tinkering Blog — March 18, 2012 @ 7:45 am