So what was a feature? Let’s see if I can come up with a good explanation. I think it is here explanations often is too vaugue.
A feature is zero or more elements. Elements can be list and/or what a lists consists of like content type, list items and fields, but also other kind of site content. See the list below.
A feature must be activated. If the feature has zero elements then it is only code in the activation/deactivation eventhandler that makes up the feature, but that code is optional.
With that definition a feature is a plug-in to sharepoint, that adds more than the standard elements.
In the below table the features are printed from a sample WSS site collection. The elements are printed from MSDN.
|Many lists are implemented as features. Features must be activated in the context of a Farm, a Web app, a Site Collection or a Site. Features are configured in feature.xml files which includes zero or more elements.||One feature can be made of elements.|
|WebPageLibrary||Content Type Binding|
|PictureLibrary||Custom Action //menu item|
|DataSourceLibrary||Custom Action Group|
|AnnouncementsList||Feature/Site Template Association|
|TasksList||Hide Custom Action|
If I want to make a simple feature then which elements should it contain?
I like that question because on this HowTo http://msdn.microsoft.com/en-us/library/ms475286.aspx you are presented with a feature with an element of type Custom Action. And what the he.. is that? Three WSS words meaning nothing to a newbie. A better word for the Custom Action element could be MenuItem. Custom Action adds an item to a menu.
With the above table you get a bigger picture. A feature is like Lego. You build blocks like an AnnouncementsList from smaller elements.
When you examine AnnouncementsList inside the feature directory %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES you find:
Feature.xml: – Notice a link to an xml file containing elements.
<Feature Id="00BFEA71-D1CE-42de-9C63-A44004CE0104" Title="$Resources:core,announcementslistFeatureTitle;" Description="$Resources:core,announcementslistFeatureDesc;" Version="188.8.131.52" Scope="Web" Hidden="TRUE" DefaultResourceFile="core" xmlns="http://schemas.microsoft.com/sharepoint/"> <ElementManifests> <ElementManifest Location="ListTemplates\Announcements.xml"/> </ElementManifests> </Feature>
ListTemplates\Announcements.xml: – Notice the type of an included element is ListTemplate.
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <ListTemplate Name="announce" Type="104" BaseType="0" OnQuickLaunch="TRUE" SecurityBits="11" Sequence="320" DisplayName="$Resources:core,announceList;" Description="$Resources:core,announceList_Desc;" Image="/_layouts/images/itann.gif"/> </Elements>
But the long story is put in Announce\schema.xml in where you find a long xml script code. I certainly hope this is generated code – it seems too long and complex to handwrite (1706 lines!).
This didn’t make us more wiser than to show some of the pieces needed to make a template for an announcement list. But it should have broadened our vision of what a feature is.
So now we should go on with the
MSDN HowTo Create a simple feature – Type Custom Action
So what is the idea of following that article? Well I can add some comments that I otherwise has to look else where to find.
The project is made without WSPBuilder. With WSPBuilder you get a template as a starting point and deployment facilities are included in the project menu. See this article.
The project includes following files and folders:
The \Template\feature\ folders is where the files in them should be deployed in the 12Hive.
The .snk key file is not needed here since we don’t have code to install in the GAC, but a feature will often have some code.
<!--<Feature //http://msdn.microsoft.com/en-us/library/ms436075.aspx Id="" //create a new GUID here Scope="Farm | WebApplication | Web | Site" How many sites will use this feature at the same time? xmlns="http://schemas.microsoft.com/sharepoint/" Title="" //Name of the feature project Description="bla - bla" //Optional Hidden="TRUE | FALSE" //Optional. false if the feature should be activated manually, true if the feature should be activated by script ImageUrl="" //Optional - An image for the feature to be activated in the ??? menu ReceiverAssembly="" //Optional - use it if you overwrite events for activating/deactivatting the feature ReceiverClass="" //Optional - use it if you overwrite events for activating/deactivatting the feature Version="184.108.40.206" //Optional SolutionId = "" //Optional Creator="" //Optional ActivateOnDefault = "TRUE" | "FALSE" //Optional. Only for Farm or WebApplication. AlwaysForceInstall = "TRUE" | "FALSE" //Optional AutoActivateInCentralAdmin = "TRUE" | "FALSE" //Optional. Not for Farm. RequireResources = "TRUE" | "FALSE" //Otional - see Msdn DefaultResourceFile = "" //Optional >--> <Feature Id="D80FE5C7-5838-4a39-9047-6E091E227486" Scope="Web" xmlns="http://schemas.microsoft.com/sharepoint/" Title="Title for Feature-CustomAction-UrlActionTemplate" Description="This is a Feature template" Hidden="FALSE" ImageUrl="ACL16.gif" Version="220.127.116.11" SolutionId = "Feature-CustomAction-UrlActionTemplate" Creator="rasor" > <ElementManifests> <ElementManifest Location="elements.xml" /> </ElementManifests> </Feature>
In the feature file for this feature there are a few things to notice:
- The scope is web. Then the feature should be activated in each site under Site Settings – Site Features.
If the scope was site, then the feature should be activated in a site collection under Site Settings – Site Collection Features.
- There are elements included in this feature in the file elements.xml.
- There is no eventhandler code for activate/deactivate, since ReceiverAssembly and ReceiverClass is not used.
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <!--http://msdn.microsoft.com/en-us/library/ms474383.aspx - Element types http://msdn.microsoft.com/en-us/library/ms465980.aspx - CustomAction Defs http://msdn.microsoft.com/en-us/library/ms460194.aspx - CustomAction Element http://msdn.microsoft.com/en-us/library/bb802730.aspx - Location http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spbasepermissions.aspx - Rights --> <!--<CustomAction //Scope all 4 Title = "" //Req Location = "EditControlBlock | //item menu DisplayFormToolbar | // EditFormToolbar | // NewFormToolbar | // ViewToolbar | // Microsoft.SharePoint.StandardMenu | //Misc menues - incl SiteActions Microsoft.SharePoint.Administration.ApplicationCreated | //SPCA - App Created Page Microsoft.SharePoint.Administration.ApplicationManagement | //SPCA - Adm Mgmt Page Microsoft.SharePoint.Administration.Operations | //SPCA - Operations Page Microsoft.SharePoint.ContentTypeSettings | //Site Collection Content Type page Microsoft.SharePoint.ContentTypeTemplateSettings | //List Content Type page Microsoft.SharePoint.Create | //Create page Microsoft.SharePoint.GroupsPage | //site collection People and Groups page Microsoft.SharePoint.ListEdit | //Customize page Microsoft.SharePoint.ListEdit.DocumentLibrary | //Customize page Microsoft.SharePoint.PeoplePage | //People and Groups page Microsoft.SharePoint.SiteSettings | //Site Settings page Microsoft.SharePoint.User | //Web site Permissions page Microsoft.SharePoint.Workflows" //Workflow pages GroupId = "" //Optional. See http://msdn.microsoft.com/en-us/library/bb802730.aspx Id = "" //Optional. See http://msdn.microsoft.com/en-us/library/bb802730.aspx Sequence = "Integer" //Optional Description = "" //Optional ImageUrl = "" //Optional ContentTypeId = "" //Optional - Don't use this parm. User RegistrationId with RegistrationType=ContentType ControlAssembly = "" //Optional ControlClass = "" //Optional ControlSrc = "" //Optional RegistrationType = "ContentType | FileType | List | ProgId" //Optional RegistrationId = "" //Optional RequireSiteAdministrator = "TRUE" //Optional Rights = "" //Optional ShowInLists = "TRUE" //Optional ShowInReadOnlyContentTypes = "TRUE" //Optional ShowInSealedContentTypes = "TRUE" //Optional > </CustomAction>--> <CustomAction Title="Goto MS" Location="ViewToolbar" Id="View List Toolbar CustActLink" Sequence="20" RegistrationType="List" RegistrationId="104" Description="bla - bla" ImageUrl="~site/_layouts/images/next.gif" > <UrlAction Url="http://msdn.microsoft.com/en-us/library/ms460194.aspx"/> </CustomAction> </Elements>
Things to notice in the elements file:
- There is only one element of type CustomAction. CustomAction is a menu item.
- The menu item should be placed on the Location=ViewToolbar. This is a toolbar you see when you are in view mode and look at lists.
- Left out is GroupId, which is needed for some locations. See http://msdn.microsoft.com/en-us/library/bb802730.aspx
- The category of lists this feature applies to is generic lists (RegistrationType=”List“)
- The type of list this feature applies to is AnnouncementsLists (RegistrationId=”104“).
I guess the sharepoint team are not good a thinking object oriented since we should be presented with database ID’s.
- The menuitem also has an image – a kind of right pointing arrow. The link to the image includes a link to the site collection (~site) and a relative path to the virtual directory for application pages (_layouts).
- The title is the value shown on the menubar
- The description i a yellow pop-up
select tp_Title, tp_ServerTemplate from Wss_Content..AllLists order by tp_Title
RegistrationIds of type ContentType: http://msdn.microsoft.com/en-us/library/ms452896.aspx
RegistrationIds of type FileType: “docx” etc.
SET HIVE12="%programfiles%\common files\microsoft shared\web server extensions\12\Template" SET STSADM="%programfiles%\common files\microsoft shared\web server extensions\12\bin\stsadm" SET GACUTIL="%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil" SET PROJNAME=Feature-CustomAction-UrlActionTemplate SET TARGETSITE=http://spvm/ REM Install into GAC %GACUTIL% -if bin\debug\%PROJNAME%.dll REM Copy to TEMPLATE folder xcopy /e /y TEMPLATE\* %HIVE12% REM Install and activate feature %STSADM% -o installfeature -filename %PROJNAME%\feature.xml -force %STSADM% -o activatefeature -filename %PROJNAME%\feature.xml -url %TARGETSITE% IISRESET
You don’t have to install into GAC, since no code is used in this feature, but just leave it here, so you can use it, when you have some code included.
SET HIVE12="%programfiles%\common files\microsoft shared\web server extensions\12\Template" SET STSADM="%programfiles%\common files\microsoft shared\web server extensions\12\bin\stsadm" SET GACUTIL="%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil" SET PROJNAME=Feature-CustomAction-UrlActionTemplate SET TARGETSITE=http://spvm/ SET PROJSN="%PROJNAME%,Version=18.104.22.168, Culture=neutral, PublicKeyToken=9f4da00116c38ec5" REM UnInstall and deactivate feature %STSADM% -o deactivatefeature -filename %PROJNAME%\feature.xml -url %TARGETSITE% -force %STSADM% -o uninstallfeature -filename %PROJNAME%\feature.xml -force IISRESET REM uninstall from GAC %GACUTIL% -u %PROJSN%