Accessing Information with the Feature Object Model

SharePoint Server 2007 exposes a Feature object model that you can use to programmatically access Feature collections and extract information on Feature deployment, such as showing all activated Features within a given scope.

More Info 

For full details about Feature classes, see the "Feature Object Model" topic in the Windows SharePoint Services 3.0 Software Development Kit.

The following example displays a list of activated Feature names and GUIDs on the root site of a site collection, using the Feature class SPFeatureCollection: The first section of code sets the context for the current site collection and specifies the root web of the site collection as the site against which to check for activated Features. The second part of the code renders the output and displays the results, which include the Title and ID for each activated Feature found within the root web of the site collection. Note, in the case of using the object model to detect activated Features, any hidden Features, that is those Features hidden from the Site Features administrative page, are also exposed.

On the CD 

This code example is designed to be implemented as a Web Part. To implement and run the code, see the Active solution on the companion CD in the \Code\Chapter 26 folder. You need to recompile the project in Visual Studio, copy the DLL to the GAC, add the safe control to the Web.config file of the virtual directory to which you will deploy the Web Part, and populate the site collection Web Part Gallery with the Web Part.

 protected override void RenderContents(HtmlTextWriter writer) {     SPSite siteCollection = SPControl.GetContextSite(Context);     SPWeb site = siteCollection.RootWeb;     SPFeatureCollection siteFeatures = site.Features;     System.Globalization.CultureInfo cultureInfo = new System.Globalization. CultureInfo(1033);      foreach (SPFeature siteFeature in siteFeatures)      {          writer.Write("Title: " + siteFeature.Definition.GetTitle(cultureInfo) + "<BR>ID:" + siteFeature.DefinitionId.ToString() + "<BR><BR>");       }    } 

Figure 26-24 shows the resultant Web Part rendered on the Home page of the Fabrikam site.

image from book
Figure 26-24: Deployed Web Part showing activated Features in site

Microsoft Office Sharepoint Server 2007 Administrator's Companion
MicrosoftВ® Office SharePointВ® Server 2007 Administrators Companion
ISBN: 0735622825
EAN: 2147483647
Year: 2004
Pages: 299

Similar book on Amazon
Microsoft Office SharePoint Server 2007 Best Practices
Microsoft Office SharePoint Server 2007 Best Practices
Microsoft SharePoint 2010 Administrator's Companion
Microsoft SharePoint 2010 Administrator's Companion
Professional SharePoint 2010 Administration
Professional SharePoint 2010 Administration
Inside Microsoft  Office SharePoint  Server 2007
Inside Microsoft Office SharePoint Server 2007 © 2008-2017.
If you may any questions please contact us: