More a small development note for myself since I generally end up using all the columns in a list when developing with SPGridView’s.
private static void GenerateColumns(this SPGridView gridView, SPList list )
gridView.AutoGenerateColumns = false;
foreach( var column in from string fieldname in list.DefaultView.ViewFields
select list.Fields.GetFieldByInternalName( fieldname )
select new BoundField
DataField = field.StaticName,
HeaderText = field.Title
gridView.Columns.Add( column );
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 WebsPreppedForIteration()
var collection = new List();
foreach (SPSite x in SPFarm.Local.Services.OfType().SelectMany
(svc => ((svc).WebApplications.Where
(webApp => !webApp.Properties.ContainsKey(“Microsoft.Office.Server.SharedResourceProvider”)).SelectMany
(webApp => webApp.Sites.Cast()))).Where
(x => !Equals(x.RootWeb.Title, “Central Administration”)))
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?
I needed a quick and dirty way to go through the SPWebService.AdministrationService to get a collection SPWebService.WebApplications and then test whether the SPWebApplication is the Central Administration application. To do this you need to use the SPWebApplication.IsAdministrationWebApplication boolean property. To keep things succinct you can just chain a LINQ query to return the representative SPSite of the desired administrative SPWebApplication. Consider the following RetrieveAdminApplication method that is consuming a SPContext object as a parameter:
public static SPSite RetrieveAdminApplication(SPContext context)
Where(application => application.IsAdministrationWebApplication).FirstOrDefault().
This is probably not ideal, but will work!