Company      |       Articles & Research      |      Services      |      Software      |      Contact

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:

C#:
  1. public static List<SPWeb> WebsPreppedForIteration()
  2. {
  3. var collection = new List<SPWeb>();
  4. foreach (SPSite x in SPFarm.Local.Services.OfType<SPWebService>().SelectMany
  5. (svc => ((svc).WebApplications.Where
  6. (webApp => !webApp.Properties.ContainsKey("Microsoft.Office.Server.SharedResourceProvider")).SelectMany
  7. (webApp => webApp.Sites.Cast<SPSite>()))).Where
  8. (x => !Equals(x.RootWeb.Title, "Central Administration")))
  9. {
  10. collection.AddRange(x.RootWeb.Webs.Cast<SPWeb>());
  11. }
  12. return collection;
  13. }

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?

share save 171 16 Enumerating All SPWebs In SPFarm.Local Into Strongly Typed Collection

Related posts:

  1. Typed Dictionary With SharePoint Web Titles And Typed SPListItem Collection
  2. Solving SharePoint FullTextSqlQuery Wrong Site Collection Error
  3. Return Current User SharePoint MySite URL
  4. Strongly Typed SharePoint List Collections By Template Type
  5. IT Consulting Ethics – Part 3 – Benefit-Cost Analysis and Government Considerations

3 Comments »

  1. 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

  2. [...] 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

  3. [...] 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

RSS feed for comments on this post. TrackBack URL

Leave a comment