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:

[csharp]

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”)))
{
collection.AddRange(x.RootWeb.Webs.Cast());
}
return collection;
}

[/csharp]

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

Solving SharePoint FullTextSqlQuery Wrong Site Collection Error

The FullTextSqlQuery class is really nice for building readable query statements, all in familiar SQL syntax. While it’s a lot easier to use when querying data, the returned content is limited to that which has been indexed by SharePoint.

This is something to keep in mind, the indexing part. Consider the following code snippet, delivered as a generic static method:

[csharp]

RunQuery(“SELECT FileExtension, ContentClass, IsDocument, title, path, author from scope() “);

public static RunQuery(string queryText)
{
FullTextSqlQuery query = new FullTextSqlQuery(SPContext.Current.Site);
query.ResultTypes = ResultType.RelevantResults;
query.QueryText = queryText;
ResultTableCollection resultCollection = query.Execute();
DataTable resultDataTable = new DataTable();
ResultTable resultTable = resultCollection[ResultType.RelevantResults];
resultDataTable.Load(resultTable);
}
[/csharp]

While running such code, you may encounter a problem where the wrong site collections are returning data. It may crop up in the form of a particular site collection being always used, or a weird permutation of site collections. If this problem occurs, there are generally two causes of the problem.

1) Ensure you are referencing Microsoft.Office.Server.Search.Query.FullTextSqlQuery and not Microsoft.SharePoint.Search.Query.FullTextSqlQuery
2) Ensure in Central Administration / Site Settings / Search And Offline Availability /Indexing Site Content the content is being indexed.

Share