SPWebApplication.Sites Property
Gets the collection of all site collections in the Web application.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
Property Value
Type: Microsoft.SharePoint.Administration.SPSiteCollectionAn SPSiteCollection object that represents the collection of site collections.
SPWebApplication.Sites And LINQ
When using the SPWebApplication.Sites property it is important to realize that with the introduction of LINQ with SharePoint, you no longer have to Cast<T> (types) to achieve IQueryable support.
So, instead of this example SharePoint Feature activation code:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parent as SPSite;
if (site != null)
{
SPWebApplication webApp = site.WebApplication;
string targetUrl = string.Empty;
foreach (SPSite rootSiteSearch in webApp.Sites.Cast<SPSite>().Where
(rootSiteSearch => rootSiteSearch.RootWeb.Title == "Website Example"))
{
targetUrl = rootSiteSearch.RootWeb.Url;
}
Uri x = new Uri(targetUrl + Constants.CustomizedMasterUrl);
SPWeb rootWeb = site.RootWeb;
}
}
can instead by written as:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parent as SPSite;
if (site != null)
{
SPWebApplication webApp = site.WebApplication;
string targetUrl = string.Empty;
foreach (SPSite rootSiteSearch in webApp.Sites.Where
(rootSiteSearch => rootSiteSearch.RootWeb.Title == "Website Example"))
{
targetUrl = rootSiteSearch.RootWeb.Url;
}
Uri x = new Uri(targetUrl + Constants.CustomizedMasterUrl);
SPWeb rootWeb = site.RootWeb;
}
}
Adam Buenz
SharePoint Foundation MVP - http://www.sharepointsecurity.com
- 10/18/2010
- Adam Buenz - MVP
- 10/18/2010
- Adam Buenz - MVP