SharePoint Features: The Basics

  • Items that were previously contained within a large site definition file have been broken out as separate elements within Features. An element is an atomic unit within a Feature. A Feature.xml file typically points to one or more XML files whose top-level tag contains definitions for elements that support the Feature. Elements in Windows SharePoint Services 3.0 often correspond to what were discrete nodes in the Onet.xml or Schema.xml file of the previous version. There are several types of element—for instance, a custom menu item or an event handler.
  • A feature can provide the combined functions of elements.
  • To implement a Feature you add a subfolder containing a Feature definition within the Features setup directory (Local_Drive:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATEFEATURES). The Feature subfolder includes a Feature.xml file that defines the base properties of the Feature and lists elements bound to it, such as XML files containing element manifests and any other supporting files. A Feature folder may contain only a Feature.xml file, or it may contain a Feature.xml file and any number of supporting element files, including XML files, but also .aspx, .htm, .xsn, .resx, .dll, and other file types.
  • When you create a folder within the Features directory through Windows Explorer by right-clicking a folder, pointing to New, and then clicking Folder, the new folder does not have inherited permissions. If you deploy a Feature in the folder, then some Windows SharePoint Services pages, such as for site settings or list views, throw an exception. You can fix this problem by right-clicking the new folder, click Properties, click Security, and then click Advanced. On the Permissions tab, delete uninherited permissions from the folder. You can also fix this problem by creating the new folder at the command prompt through the md command.
  • After creating the Feature folder, you can install and activate the Feature through command-line operations of stsadm.exe, or through the object model. You can also activate a Feature through the user interface. Installing a Feature makes its definition and elements known throughout a server farm, and activating the Feature makes the feature available at a particular scope.

SharePoint EventHandler Basics

NEW IN 3.0:

• You can use pre-synchronous and post-asynchronous modes to handle events.
• You can register events at the file, list, and Web site levels.
• You can register multiple events per item.
• You can cancel pre-synchronous events and display custom error messages.
• You can register item events on generic lists, as well as on document libraries.
• You can declaratively register events per list type or content type.
• In addition to trapping standard list item events (for example, ItemAdding, ItemDeleting, or ItemUpdating), you can trap schema events (such as adding, removing, or updating columns), as well as Web site and site collection deletion

CREATING AN EVENTHANDLER:

• Create an event handler assembly by creating a class library. Add reference to the Microsoft.SharePoint.dll and inherit from the Microsoft.SharePoint.SPitemEventReceiver base class:
Public class SimpleEventHandler : SPItemEventReceiver, …

REGISTERING AN EVENT HANDLER:

•.Add
•By list template ID
•Declaratively by content type

NOTE: must be strongly named and registered in the GAC.