Monday, August 24, 2009

What is feature in SharePoint

A SharePoint Feature is a functional component that can be activated and deactivate at various scopes throughout a SharePoint instances, such as at the farm, site collection, web, etc. Features have their own receiver architecture, which allow you to trap events such as when a feature is installing, uninstalling, activated, or deactivated. The element types that can be defined by a feature include menu commands, link commands, page templates, page instances, list definitions, list instances, event handlers, and workflows.
The two files that are used to define a feature are the feature.xml and manifest file(elements.xml).
The feature XML file defines the actual feature and will make SharePoint aware of the installed feature.
The manifest file contains details about the feature such as functionality.
The "Feature" is one of the major concepts in WSS3.0. The Feature is a container of various defined extensions for SharePoint.

A Feature can include any number of files, but it must include a Feature.xml file. The Feature.xml file, or Feature manifest, is the driver of the Feature, and this is the first file SharePoint looks at when invoking a Feature.
Features are organized in folders under the Features directory located under 12 hives; Where SharePoint Server 2007 puts all of its system files, at the following path: %SystemDrive%\Program Files\Common Files\Microsoft Shared\web server extensions\12.
In addition to the Feature.xml file, Features can include sub-folders and supporting files, such as element files that include for example, event handler references, ASPX pages deployed as part of the Feature, ASCX files, and DLL and RESX files.

For example, i required a custom feature, which add menu commands in the Custom List and after clicking on the custom link, control goes to custom page called DisplayListItems.aspx. In the DisplayListItems.aspx page, we will display the URL of site, list name and current loggedin user details. The screenshot of Menu Command given below:

Menu Command:



See the screenshot below of Feature.xml,DisplayList.xml(manifest file),DisplayListItems.aspx and DisplayListItems.aspx.cs.

Feature.xml:


SCOPE AND ALLOWED FEATURES

Web (Web site)

* Control
* Custom Action
* Custom Action Group
* Hide Custom Action
* List Instance
* List Template
* Module (File Set)
* Receiver

Site (site collection)

* Content Type
* Content Type Binding
* Control
* Custom Action
* Custom Action Group
* Feature/Site Template Association
* Field
* Hide Custom Action
* List Template
* Module (File Set)
* Workflow

WebApplication (Web application)

* Control
* Custom Action
* Custom Action Group
* Document Converter
* Feature/Site Template Association
* Hide Custom Action

Farm (farm)

* Control
* Custom Action
* Custom Action Group
* Feature/Site Template Association
* Hide Custom Action

In a Feature.xml file, the Feature element defines a Feature and specifies the location of assemblies, files, dependencies, or properties that support the Feature. In the above screenshot
ElementManifests Element (Feature):Contains references to element manifests (in our case name of Element manifest is DisplayList.xml) and element files that contain definitions for the Feature elements.

The attributes of above mentioned Feature.xml are:

AttributeDescription
Id
Required Text.Contains the globally unique identifier (GUID) for the Feature.
Title
Optional Text. Returns the title of the Feature. Limited to 255 characters.
Description
Optional String. Returns a longer representation of what the Feature does.
Version
Optional Text. Specifies a System.Version-compliant representation of the version of a Feature. This can be up to four numbers delimited by decimals that represent a version.
Scope
Required Text. Specifies the scope in which the Feature can be activated and contains one of the following values: Farm (farm), WebApplication (Web application), Site (site collection), Web (Web site).



DisplayList.xml(manifest file):



The above element manifest file specifies a support file required for the Feature.

The attributes of above mentioned DisplayList.xml are:

AttributeDescription
Custom Action
A custom action represents a link, toolbar button, menu item, or any control that can be added to a toolbar or menu that a user sees. Custom actions can be bound to list type, content type, file type, or programmatic identifier (ProgID).
Id
The unique identifier for the custom action.
Description
Description of the feature.
RegistrationType
Optional Text. Specifies the registration attachment for a per-item action. Possible values include:

* ContentType
* FileType
* List
* ProgId

RegistrationId
Optional Text. Specifies the identifier of the list or item content type that this action is associated with, or the file type or programmatic identifier (ProgID).
Location
Optional Text. Specifies the location of this custom action, for example, "Microsoft.SharePoint.SiteSettings". If the custom action is a menu item or toolbar button, then the possible options include EditControlBlock, NewFormToolbar, DisplayFormToolbar, and EditFormToolbar.

If contained within a custom action group, the value of the Location attribute must equal the location of the CustomActionGroup element.

See Default Custom Action Locations and IDs for a list of the default custom action locations that are used in Windows SharePoint Services.
GroupId
Optional Text. Identifies an action group that contains the action, for example, "SiteManagement". If contained within a custom action group, the value of the GroupId attribute must equal the group ID of the CustomActionGroup element.

See Default Custom Action Locations and IDs for a list of the default custom action group IDs that are used in Windows SharePoint Services.
Sequence
Optional Integer. Specifies the ordering priority for actions.
Rights
Optional Text. Specifies a set of rights that the user must have in order for the link to be visible, for example, "ViewListItems,ManageAlerts". If not specified, then the action always appears in the list of actions. To specify multiple rights, separate the values by using commas. The set of rights are grouped logically according to AND logic, which means that a user must have all the specified rights to see an action. For a list of possible values, see Microsoft.SharePoint.SPBasePermissions.
ImageUrl
Optional Text. Specifies a virtual server relative link to an image that presents an icon for the item.
Title
Required Text. Specifies the end user description for this action.
UrlAction
is used to redirect users if they click on the link.


The following table shows the default list template integer IDs that you can use in defining the RegistrationId :

List Template Id List Template
100 Generic list
101 Document library
102 Survey
103 Links list
104 Announcements list
105 Contacts list
106 Events list
107 Tasks list
108 Discussion board
109 Picture library
110 Data sources
111 Site template gallery
113 Web Part gallery
114 List template gallery
115 XML Form library
120 Custom grid for a list
200 Meeting Series list
201 Meeting Agenda list
202 Meeting Attendees list
204 Meeting Decisions list
207 Meeting Objectives list
210 Meeting text box
211 Meeting Things To Bring list
212 Meeting Workspace Pages list
300 Portal Sites list
1100 Issue tracking
2002 Personal document library
2003 Private document library



DisplayListItems.aspx file:

The .aspx contains only two server side ASP label for displaying user details and list name.


DisplayListItems.aspx.cs file:


In the .cs i have written the code for accessing site url/user details and list name on Page Load event.

Packaging the Feature:

In SharePoint Server 2007, Solutions are used to package and deploy Features, Site Definitions, Web Parts, Template Files, Assemblies and Code Access Security (CAS) policies to SharePoint front-end servers.

Steps for creating a Solution Package are described below:

* Create Manifest.XML file as part of the same project, which contains information Solution and path of feature files as part of the overall solution.




* Create the Diamond Discovery File/diamond directive file i.e. DDF file, which contains information to compress files into a CAB file.



* In the windows command prompt, run MakeCab.Exe on the DDF file to generate the WSP file. Note: MakeCab.Exe file can be downloaded from the Microsoft Site and should be copied into the same directory containing the Visual Studio Project Files.

* See screenshot below to make WSP file by using MakeCab.EXE command line utility.


Deploying the Features:

Steps for deploying a Solution Package are described below:

* Use the STSADM.EXE command line tool to add WSP file into the SharePoint Solution Store.
  1. stsadm -o addsolution -filename D:\Amit_Code\SharePoint\Amit\ReadListFeature\ReadListFeature.wsp
  2. stsadm -o deploysolution -name ReadListFeature.wsp -immediate
  3. stsadm -o installfeature -name ReadList
  4. stsadm -o activatefeature -name ReadList -url "http://amitkumarmca04.blogspot.com/sites/AMIT"
With the help of above steps Feature ReadList would be installed in your site.

Deactivating and Uninstalling the Solution:

You can also deactivate a particular feature on your site or web application, or you can uninstall a feature, which completely removes the feature from your SharePoint deployment. Features can be deactivated either through the administrative user interface or by using the STSADM.EXE command-line tool.

Deactivating the Feature by administrative user interface:
  • Browse the site where you want to deactivate the feature, Click Site Actions, and under Site Administration, click Site Features.
  • On the Site features page, locate the Feature you want to deactivate and click the Deactivate button to deactivate the Feature




Deactivating the feature by using the STSADM.EXE command-line utility:

Deactivating the feature by using the STSADM.EXE command-line utility:

stsadm -o deactivatefeature -name ReadList -force -url "http://amitkumarmca04.blogspot.com/sites/AMIT"

Uninstalling the Feature by using the STSADM.EXE command-line utility:

stsadm -o uninstallfeature -name ReadList -force

Delete solution using the STSADM.EXE command-line utility:

stsadm -o deletesolution -name ReadListFeature.wsp -override

With the help of this article, you will be able to write custom Features/ deploy custom feature with the help of SharePoint Solution Package (.wsp) and also able to de-activate or uninstall an existing feature.
Share:

0 comments:

About Me

My photo
Based in Bangalore, INDIA, Amit is a MCC. He has an MCA from the U.P.T.U., INDIA and holds Microsoft certifications including SharePoint 2007/2010/2013. He is an contributor to MSDN and http://amitkumarmca04.blogspot.com/. Amit have experience in SharePoint,ASP.Net with C#, Classic ASP, VB,Macros,HTML,JavaScript,JSON,BootStrap and AngularJS.

Followers

Labels