Which code segment should you add to the Web Part?

You create a Feature named Feature1. Feature1 is activated in a SharePoint site.

You create a Web Part that contains the following code.

SPSite site = new SPSite(“http://intranet/site1”);
SPWeb web = site.OpenWeb();
SPFeatureDefinition feature = SPFarm.Local.FeatureDefinitions[“Feature1”];

You need to modify the Web Part to activate Feature1 in Site1 only.

Which code segment should you add to the Web Part?

You create a Feature named Feature1. Feature1 is activated in a SharePoint site.

You create a Web Part that contains the following code.

SPSite site = new SPSite(“http://intranet/site1”);
SPWeb web = site.OpenWeb();
SPFeatureDefinition feature = SPFarm.Local.FeatureDefinitions[“Feature1”];

You need to modify the Web Part to activate Feature1 in Site1 only.

Which code segment should you add to the Web Part?

A.
site.Features.Add(feature.Id);

B.
site.WebApplication.WebService.Features.Add(feature.Id);

C.
web.Features.Add(feature.Id);

D.
web.Site.WebApplication.WebService.Features.Add(feature.Id);

Explanation:
MNEMONIC RULE: “add feature to http://intranet/site1”

This question is confusing. site object is a SharePoint site collection with http://intranet/site1 being the root site (or root web) of this collection.
The statement “activate Feature1 in Site1 only” makes it unclear how to treat “Site1” — as a site collection or as a root web.

However, the second sentence of this question states: “Feature 1 is activated in SharePoint site”. Well, SPWeb class represents SharePoint website.
That’s why I picked Answer C, and you are free to disagree with me.

It is possible that Answer A is the correct one for this question.



Leave a Reply 1

Your email address will not be published. Required fields are marked *


AL

AL

which is the correct answer?