Which code segment should you use?

You are creating a Web Part. The Web Part will be used in a SharePoint subsite that has the URL http://www.contoso.com/hr.

You need to ensure that the Web Part activates a Feature in the subsite without causing a memory leak.

Which code segment should you use?

You are creating a Web Part. The Web Part will be used in a SharePoint subsite that has the URL http://www.contoso.com/hr.

You need to ensure that the Web Part activates a Feature in the subsite without causing a memory leak.

Which code segment should you use?

A.
SPFeatureCollection featuresCollect = SPContext.Current.SiteFeatures;
featuresCollect.Add(new Guid(“xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”), true);

B.
SPFeatureCollection featuresCollect = SPContext.Current.WebFeatures;
featuresCollect.Add(new Guid(“xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”), true);

C.
SPSite web = new SPSite(“http://www.contoso.com/hr”);
SPFeatureCollection featureCollect = web.Features;
featureCollect.Add(new Guid(“xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”), true);

D.
SPWeb web = new SPSite(“http://www.contoso.com/hr”).OpenWeb();
SPFeatureCollection featureCollect = web.Features;
featureCollect.Add(new Guid(“xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”), true);

Explanation:
MNEMONIC RULE: “no memory leak = SPContext; subsite = WebFeatures”

Gets the activated site features of the Microsoft SharePoint Foundation context.

SPContext.WebFeatures Property
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spcontext.webfeatures.aspx



Leave a Reply 0

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