Sunday, November 30, 2008

SharePoint Feature

Feature is mechanism that SharePoint used to deploy customized components. The built in components like document list, team site also deployed using feature. So basically, everything can be deployed as feature, for example list definition, content type, site column, workflow and etc, except a site template. The core of the it are two files feature.xml and elements.xml.

When you deploy features, you put all your files into the a folder, and organize the folder with this structure, CONTROLTEMPLATES, FEATURES\FEATURE_NAMES, IMAGES. The content of the folder will copied to the Template folder(c:\program files\common files\microsoft shared\web server extensions\12\Template).

The elements.xml has lots of element. But one of common use is deploying files by using Module element. You can deploy files like the following.

<Module Path="PageTemplates" Url="SitePages" > <!-- provision standard pages --> <File Url="Page01.aspx" Type="Ghostable" /> <File Url="Page02.aspx" Type="Ghostable" /> <File Url="Page03.aspx" Type="Ghostable" /> <File Url="Page04.aspx" Type="Ghostable" /> <File Url="Page05.aspx" Type="Ghostable" /> <File Url="Page06.aspx" Type="Ghostable" /> <!-- provision Web Part pages --> <File Url="WebPartPage.aspx" Name="WebPartPage01.aspx" Type="Ghostable" /> <File Url="WebPartPage.aspx" Name="WebPartPage02.aspx" Type="Ghostable" /> <!-- provision Web Part page with Web Parts inside --> <File Url="WebPartPage.aspx" Name="WebPartPage03.aspx" Type="Ghostable" > <!-- Add a Web Part to left zone --> <AllUsersWebPart WebPartZoneID="Left" WebPartOrder="0"> <![CDATA[ <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" xmlns:cewp="http://schemas.microsoft.com/WebPart/v2/ContentEditor"> <Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly> <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName> <Title>Yet Another Web Part is Born</Title> <FrameType>TitleBarOnly</FrameType> <cewp:Content> This Web Part was added through declarative logic </cewp:Content> </WebPart> ]]> </AllUsersWebPart> <!-- Add a Web Part to right zone --> <AllUsersWebPart WebPartZoneID="Right" WebPartOrder="0"> <![CDATA[ <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" xmlns:iwp="http://schemas.microsoft.com/WebPart/v2/Image"> <Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly> <TypeName>Microsoft.SharePoint.WebPartPages.ImageWebPart</TypeName> <FrameType>None</FrameType> <Title>Watch My Gears Run</Title> <iwp:ImageLink>/_layouts/images/GEARS_AN.GIF</iwp:ImageLink> </WebPart> ]]> </AllUsersWebPart> </File> </Module>

No comments:

Post a Comment