SharePoint of the Day #19

You can activate features through code by adding the GUID of the feature to the SPWeb, SPSite, or SPWebApplication object. You can also check if a feature is activated by checking the Features collection for the same GUID value:

Guid g = new Guid(”d2b48bc4-9d29-4090-960c-79c2852cfd65″);
if (web.Features[g] == null) web.Features.Add(g);

To activate features on the Farm level you must add the GUID to the SPWebApplication.WebService object. the SPWebApplication class is in the Microsoft.SharePoint.Administration namespace:

SPWebApplication app = web.Site.WebApplication;
app.WebService.Features.Add(g);

Post to Twitter Post to Delicious Delicious Post to Digg Digg This Post

Posted under Developer

This post was written by spotd on April 27, 2009

Tags:

Like this tip? Hate it? Vote here

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

What do you think if this tip?

Name (required)

Email (required)

Website

Comments

More Blog Post

Previous Post: SharePoint of the Day #18