Tuesday, August 21, 2012

Creating Dependent Features in SharePoint

In a recent project, had to create a feature which provisions bunch of Lists, Libraries and Pages with custom web parts. Those custom web parts also deployed as feature based solutions. So the requirement is: Activate the features which brings the custom web parts first, and then activate the feature which creates the pages with custom web parts.

Problem: If the user tries to activate the Main feature- which creates web part pages with custom web parts, with out activating a feature which brings the custom web part: Boom - Error!

Here comes the solution: Feature Activation dependency! How to Implement? Simple! just include the  <ActivationDependencies> in Feature.xm

<?xml version="1.0" encoding="utf-8"?>
<Feature  Id="2cec1d22-290f-41b2-a14b-164a82d43b04"
          Title="Crescent Project Site Template"
          Description="Feature for Crescent project site Template"
          Scope="Web" >

<!--Set the activation dependency for Custom web parts feature -->
    <ActivationDependency FeatureId="GUID-OF-THE-DEPENDENT-FEATURE"/>
    <ElementManifest Location="elements.xml"/>

Important: If a dependent feature is Hidden, then it will be activated automatically when we activate the parent feature. If not, SharePoint will prompt the "Required Feature" page, instructing to activate the dependent feature first. We can't have <ActivationDependencies> In a Parent feature which has Hidden=TRUE attribute.
Dependent Features in SharePoint
Another frequent use of Feature Activation Dependency is: Page layouts!

Say, We've one Feature for Page Layouts and another for Custom content types. Custom Content types are the base for Page layouts (In another words, Page layout fields are from Custom content type). So we need Feature Activation Dependency here as well.

Further MSDN Readings:

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...