Sep 19, 2009

Installing webpart as a feature

Another article in the series of exploring the power of features,In this article we installing webpart as feature.

Steps for creating the feature has already been explained in the previous post.Here is

Feature.xml

<?xml version="1.0" encoding="utf-8"?>

<Feature Id=" 8425EAF7-6ACE-4597-83C7-831CA8614D6D" Title="MySampleWebPart"

Description="Here is my sample web part"

ImageUrl="GenericFeature.gif"

Scope="Site" xmlns="http://schemas.microsoft.com/sharepoint/"> <ElementManifests>

<ElementManifest Location="elements.xml" />

</ElementManifests>

</Feature>

Element.xml

<?xml version="1.0" encoding="utf-8"?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<Module

Name="WebPartPopulation"

List="113"

Url="_catalogs/wp"

RootWebOnly="TRUE">

<File Url="MySampleWebPart.dwp" Type="GhostableInLibrary" />

</Module>

</Elements>

Note: Here in the Url ,we have to give the path of the dwp file of the webpart ,so along with feature.xml and element.xml put the dwp file of the webpart also in the features folder and copy this folder in the 12 hive .

RootWebOnly attribute is true here means this webpart will be available only at the root level not at the subsite level.This can be changed to sub web level also.

Then install and activate the feature.

Make safe control entry in the web.config file

This feature will be available in the webpart gallery,we have to populate this feature before using

Enjoy!!!

No comments:

Post a Comment