INTRODUCTION
Continuing from my previous post http://www.sharepointblogs.com/tommysegoro/archive/2008/09/14/sharepoint-solution-syntax.aspx I will discuss further on the syntax required for creating other elements of Sharepoint. In my previous posting, I've mentioned to you about how to create site definition, master pages, page layouts, content types and fields using feature. In this posting, I will mention about creating web parts, event receivers and feature receivers.
WEB PARTS
To create web parts you will need the following structure:
Inside HelloWorldWebPart.webpart you have:
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="WSPBuilder.WebParts.HelloWorldWebPart, WSPBuilder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6109cdf7233db6c5" />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<!-- standard Web Part properties -->
<property name="ChromeType" type="chrometype">Default</property>
<property name="Title" type="string">Hello World Web Part</property>
<property name="Description" type="string">Use to create classic Hello World excitement</property>
<property name="CatalogIconImageUrl" type="string">/_layouts/images/IMAGE.GIF</property>
</properties>
</data>
</webPart>
</webParts>
Inside
Elements.XML:
<
Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="WSPBuilderWebParts"
List="113"
Url="_catalogs/wp"
Path="dwp"
RootWebOnly="true">
<File Url="HelloWorldWebPart.webpart" Type="GhostableInLibrary" >
<Property Name="Group" Value="WSPBuilder Web Parts" />
</File>
</Module>
</Elements>
Inside Feature.xml:
<
Feature
Id="8E7D1D5E-4A07-4857-AD5A-EAC3D1A20391"
Title="WSPBuilder Web Parts"
Description=""
Hidden="FALSE"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="elements.xml"/>
</ElementManifests>
</Feature>
FEATURE RECEIVERS
For feature receivers you will need the following syntax:
Inside Feature.xml:
<!--
_lcid="1033" _version="12.0.4518" _dal="1" -->
<!-- _LocalBinding -->
<Feature Id="6873B8E8-848D-461d-9494-9422E354AE6B"
Title="Test Site Feature Receiver"
Description="This is the feature that sets the CompleteSharepoint.NET publishing lists without approval."
Version="1.0.0.0"
Scope="Web"
Hidden="False"
DefaultResourceFile="core"
ReceiverAssembly="SPTemplateLand, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a829755eafa973db"
ReceiverClass="SPTemplateLand.FeatureReceivers.MyFeatureReceiver"
xmlns="http://schemas.microsoft.com/sharepoint/">
</Feature>
You will then need to create your feature receiver class.
EVENT RECEIVERS
With event receiver, you need to have the following syntax:

The first feature is the feature that deploys your custom list. You can get the syntax from CustomList feature that Microsoft has deployed inside the FEATURE folder of your 12 hive.
Inside Feature.XML:
<?
xml version="1.0" encoding="utf-8"?>
<Feature Id="EAD2A016-DB17-4f7b-94CE-A3EC6CF5D815"
Title="My Custom List Feature"
Description=""
Version="1.0.0.0"
Scope="Web"
DefaultResourceFile="core"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="CustomList.xml" />
</ElementManifests>
</Feature>
Inside CustomList.XML (note the Type property):
<?
xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ListTemplate
Name="CustomList"
Type="10050"
BaseType="0"
OnQuickLaunch="TRUE"
SecurityBits="11"
Sequence="410"
DisplayName="$Resources:core,custList;"
Description="$Resources:core,custList_Desc;"
Image="/_layouts/images/itgen.gif"/>
</Elements>
The second feature is then the feature that deploys the Event Receiver feature.
Inside Feature.XML:
<?
xml version="1.0" encoding="utf-8" ?>
<Feature Id="9EF6A5A1-AF0A-494e-BB78-93BA3730E6EC"
Title="Custom List Event Receiver"
Description="An Event handler that supports the addition/modification/deletion of list items throughout various sites in the collection."
Version="1.0.0.0"
Hidden="FALSE"
Scope="Web"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="Elements.xml"/>
</ElementManifests>
</Feature>
Inside Elements.xml (note the ListTemplateId and the Type property of the event):
<?
xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers ListTemplateId="10050">
<Receiver>
<Name>SPTemplateLandEventReceivers</Name>
<Type>ItemDeleted</Type>
<SequenceNumber>10000</SequenceNumber>
<Assembly>SPTemplateLand, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3ea47656c35c3a98</Assembly>
<Class>SPTemplateLand.EventReceivers.CustomListEventReceiver</Class>
<Data></Data>
<Filter></Filter>
</Receiver>
<Receiver>
<Name>SPTemplateLandEventReceivers</Name>
<Type>ItemUpdated</Type>
<SequenceNumber>10000</SequenceNumber>
<Assembly>SPTemplateLand, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3ea47656c35c3a98</Assembly>
<Class>SPTemplateLand.EventReceivers.CustomListEventReceiver</Class>
<Data></Data>
<Filter></Filter>
</Receiver>
<Receiver>
<Name>SPTemplateLandEventReceivers</Name>
<Type>ItemAdded</Type>
<SequenceNumber>10000</SequenceNumber>
<Assembly>SPTemplateLand, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3ea47656c35c3a98</Assembly>
<Class>SPTemplateLand.EventReceivers.CustomListEventReceiver</Class>
<Data></Data>
<Filter></Filter>
</Receiver>
</Receivers>
</Elements>
You will then need to build your custom event receiver class that inherits from SPItemEventReceiver.
CONCLUSION
So there you go. Hope this helps. To be continued.
Posted
10-10-2008 3:18 PM
by
tommysegoro