understanding features and solutions webparts sharepoint2007

Upload: ashok-kumar-sah

Post on 09-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 Understanding Features and Solutions webparts sharepoint2007

    1/4

    UnderStanding Features and Solutions

    Features:Features allow reusable pieces of functionality to be created and deployed to other sites,without modifying sitetemplates.It is always better to deploy a feature in new site instead of directly embedding mountains of complexXML.Using Features, you can do everything from adding a link to the Site Settings page to creating a complete, fully

    functioning Project Management suite that can be added to any SharePoint site.

    Features are organized in folders under the Features directory located under 12 hives; Where SharePoint Server2007 puts all of its system files, at the following path: %SystemDrive%\Program Files\Common Files\MicrosoftShared\web server extensions\12.

    The two files that are used to define a feature are the feature.xml and Elements.xml .

    The feature XML file defines the actual feature and will make SharePoint aware of the installed feature. It usuallyidentifies the Feature itself and its element manifest file and sets the Feature scope to Web site.

    Elements.xml file identifies the assembly, class, and method to implement in feature.

    Add a Feature in Sharepoint:

    You can use a direct deploy of a feature in sharepoint site with stsadm.exe withstsadm -o installfeature -filename XYZEventHandler\Feature.xmlstsadm -o activatefeature -filename XYZEventHandler\Feature.xml -url http://Server/Site/Subsiteiisreset

    Reference:http://msdn2.microsoft.com/en-us/library/ms453149.aspx

    To Deploy it as solution package follow the Steps below:

    *Create Manifest.XML file as part of the same project, which contains information Solution and path of feature files aspart of the overall solution.*Create a 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.Exefile can be downloaded from the Microsoft Site and should be copied into the same directory containing the VisualStudio Project Files.

    *Add solution to Sharepoint with stsadm.exe addsolution command.

    Reference:http://www.codeproject.com/KB/sharepoint/ExtendingSPS.aspx

    Solutions:Solutions allow you to package Features in a cabinet (.cab) file and define important metadata about those Features.After a Solution is installed on a server in the farm, you can then use SharePoints Solution management features toautomate the deployment of that Solution to other sites within the farm.

    The solution manifest (always called manifest.xml) is stored at the root of a solution file.This file defines the list of features, site definitions, resource files, Web Part files, and assemblies to process. It doesnot define the file structureif files are included in a solution but not listed in the manifest XML file, they are notprocessed in any way.

    Because the solution file is essentially a .cab file, use the makecab.exe tool to create the solution package. The

    makecab.exe tool takes a pointer to a .ddf file, which describes the structure of the .cab file. The format of a .ddf fileis, declare a standard header and then enumerate, one file per line, the set of files by where they live on disk,separated by where they should live in the .cab file.

    Features & Solutions:The Feature Framework has been extended to allow developers to create custom Features. Features can bedeployed by using SharePoint Portal Server 2007 new form of deployment, namely Solution Deployment.

    Solutions are custom packages (e.g. WSP file) or redistributable CAB files, created by developers and deployed bySharePoint Administrators. Administrator can deploy Features to the individual site or to all Web front End Servers.

    http://programmingsharepoint.blogspot.com/2008/04/understanding-features-and-solutions.htmlhttp://server/Site/Subsitehttp://msdn2.microsoft.com/en-us/library/ms453149.aspxhttp://msdn2.microsoft.com/en-us/library/ms453149.aspxhttp://www.codeproject.com/KB/sharepoint/ExtendingSPS.aspxhttp://www.codeproject.com/KB/sharepoint/ExtendingSPS.aspxhttp://server/Site/Subsitehttp://msdn2.microsoft.com/en-us/library/ms453149.aspxhttp://www.codeproject.com/KB/sharepoint/ExtendingSPS.aspxhttp://programmingsharepoint.blogspot.com/2008/04/understanding-features-and-solutions.html
  • 8/8/2019 Understanding Features and Solutions webparts sharepoint2007

    2/4

    Features are a method for developers to package customisations and deploy them to the SharePoint portal. They canthen be activated and deactivated at the Site Collection level. Solutions are a way to bundle features together fordeployment.

    How to: Create an Event Handler Feature

    This example shows how to add a simple event handler that prevents items from being deleted

    from a list. Two procedures are involved in this task:

    Creating an event handler in Microsoft Visual Studio

    Adding the event handler as a Feature in Windows SharePoint Services

    To create the event handler in Visual Studio

    1. Create a new project in Visual Studio by clicking File, pointing to New, and then clicking

    Project.2. In the New Project dialog box, select Visual C# in the Project types box, select Class

    Library in the Templates box, type DeletingEventHandler in the Name box, and thenclickOK.

    3. In Solution Explorer, select DeletingEventHandler, and clickAdd Reference on the

    Project menu.4. In the Add Reference dialog box, select Microsoft.SharePoint on the .NET tab and

    then clickOK.

    5. In the Code Editor, import the Microsoft.SharePoint namespace as follows.

    using Microsoft.SharePoint;

    6. Change the name of the class to DeletingAction and make it inherit from the

    SPItemEventReceiverclass, as follows.

    public class DeletingAction : SPItemEventReceiver

    7. Add the following code within the class to override the ItemDeleting method.

    C#

    public override void ItemDeleting(SPItemEventProperties properties){

    properties.Cancel = true;properties.ErrorMessage = "Deleting items from " +properties.RelativeWebUrl + " is not supported.";}

    8. In Solution Explorer, right-click the DeletingEventHandler node, and then click

    Properties.

    9. In the Properties dialog box, click the Signing tab, select Sign the asembly, select

    Choose a strong name key file, and then click.

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spitemeventreceiver.aspxhttp://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spitemeventreceiver.itemdeleting.aspxhttp://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spitemeventreceiver.aspxhttp://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spitemeventreceiver.itemdeleting.aspx
  • 8/8/2019 Understanding Features and Solutions webparts sharepoint2007

    3/4

    10. In the Create Strong Name Key dialog box, type DeletingEventHandler.snkin the

    Key file name box, optionally specify a password for the key, and then clickOK.

    11. To build the project, clickBuild Solution on the Build menu, or press CTRL+SHIFT+B.12. Find the \DeletingEventHandler\bin\Debug folder in the Visual Studio Projects

    folder, and drag the DeletingEventHandler.dll file to Local_Drive:\WINDOWS\assembly

    to place the DLL in the global assembly cache.

    To add the event handler as a Windows SharePoint

    Services Feature

    1. Create a folder in Local_Drive:/Program Files/Common Files/Microsoft Shared/web serverextensions/12/TEMPLATE/FEATURES called DeletingEventHandler.

    2. Create a Feature.xmlfile in this folder like the following that identifies the Feature and its element manifest file andsets the Feature scope to Web site.

    Xml

    3. To replace the GUID placeholder in the previous Id attribute, generate a GUID by running guidgen.exe located inLocal_Drive:\Program Files\Microsoft Visual Studio 8.

    4. Create an Elements.xml file in the DeletingEventHandler folder that identifies the assembly, class, and method to

    implement as the event handler. This example applies the event handler to all announcements lists of a site, as specifiedby the ListTemplateId attribute. For the IDs of other default Windows SharePoint Services list template types, see theType attribute description of theListTemplateelement.

    Xml

    DeletingEventHandler ItemDeleting 10000 DeletingEventHandler, Version=1.0.0.0, Culture=neutral,PublicKeyToken=a26b5449ac4a4cf3 DeletingEventHandler.DeletingAction

    5. To get the Public Key Token of the assembly, in Windows Explorer find the DeletingEventHandler.dll file in theLocal_Drive:\WINDOWS\assembly, right-click the file, clickProperties, and on the General tab of the Properties

    dialog box, select and copy the token.

    http://msdn.microsoft.com/en-us/library/ms475601.aspxhttp://msdn.microsoft.com/en-us/library/ms475601.aspxhttp://msdn.microsoft.com/en-us/library/ms462947.aspxhttp://msdn.microsoft.com/en-us/library/ms462947.aspxhttp://msdn.microsoft.com/en-us/library/ms462947.aspxhttp://msdn.microsoft.com/en-us/library/ms475601.aspxhttp://msdn.microsoft.com/en-us/library/ms462947.aspx
  • 8/8/2019 Understanding Features and Solutions webparts sharepoint2007

    4/4

    6. At a command prompt, navigate to \Program Files\Common Files\Microsoft Shared\web serverextensions\12\BIN on the local drive, and type each of the following commands to install the Feature in the

    deployment, activate the Feature on a specified subsite, and reset Microsoft Internet Information Services (IIS) so that

    the changes take effect:7. stsadm -o installfeature -filename DeletingEventHandler\Feature.xml8.9. stsadm -o activatefeature -filename DeletingEventHandler\Feature.xml -url

    http://Server/Site/Subsite10.

    iisreset

    11. Try to delete an item in an announcements list on the specified Web site to see the effects of the event handler Feature.