SharePoint SharePoint Features & Solutions

SharePoint 2007 SharePoint Features & Solutions 26 Octob er 2014 SharePoint Features & Solutions Microsoft provides ways to extend the out of the ...
Author: Ethan Casey
3 downloads 0 Views 413KB Size
SharePoint 2007

SharePoint Features & Solutions

26 Octob er 2014

SharePoint Features & Solutions Microsoft provides ways to extend the out of the box functionality of SharePoint Portal Server 2007 e.g. Features, SharePoint Designer 2007, Windows Workflow Foundation etc. Features offer flexibility in terms of developing extended functionality such as Page Templates, List, Content Types, Web Parts, Workflow and events to new and existing SharePoint 2007 sites. Features allow you to add new functionality to SharePoint or make simple site customizations in an easy and consistent way. Features can be scoped to the Farm, Web Application, Site, and Web level depending on the purpose of the feature. The basis of a feature is implemented using a feature.xml file, but may also contain other supporting files. The main directory for all the default SharePoint Features is Local_Drive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES)” The Following figure shows an example of what the FEATURES directory looks like after you’ve installed WSS. As you can see, each feature has its own directory.

2

SharePoint Features & Solutions 

To implement a Feature you need add a subfolder containing a Feature definition within the Features setup directory (Local_Drive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES). 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.



Besides the feature.xml file, a feature usually contains one or more additional XML files (elements.xml, for instance) that define the actual elements that make up the feature. The directory can also contain other types of files for things like list definitions and page templates as well as resources like images, cascading style sheets, and JavaScript.

3

SharePoint Features & Solutions 



A feature is defined using a Feature element that contains several attributes, such as Id, Title, Description, Version, Scope, Hidden, and ImageUrl. You must create a new GUID for the Id attribute so your feature can be uniquely identified. You create the feature’s Title and Description attributes using user-friendly text. These attributes are displayed directly to users on the WSS. Id - one GUID (Globally Unique Identifier) For example Id="40E34ABE-8804-4437-A23A-C561FDEE6D0A"





Scope – Farm, WebApplication, Site, Web

The Scope defines the context in which the feature can be activated and deactivated. The feature with a scope equal to Web, which means it can be activated and deactivated within the context of a site. If, instead, Scope value of Site, your feature can then be activated and deactivated within the scope of a site collection. The two other possible scopes for defining a feature are WebApplication scope and Farm scope.

4

SharePoint Features & Solutions Hidden attribute has a value of FALSE. This means that, once installed within the farm, the feature can be seen by users who might want to activate it. If you create a feature with the Hidden attribute value set to TRUE, the feature will be hidden in the list of available features shown to users. The ImageUrl attribute has a value that points to one of the graphic images that is part of the basic WSS installation. This image will be shown next to the feature in the UI. Go to the Properties toolpane and click on the button for the Schema field (see Figure 1), select the Add button in the XSD Schemas dialog, browse to the wss.xsd. This will enable intellisense in your XML files. The xsd file can be found in the location C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML

5

SharePoint Features & Solutions 

Another part is referencing the element.xml between the selected XML tag.



One example of the basic feature.xml file is given below:





   

 



6

SharePoint Features & Solutions 

Example of the Elements.xml file





     

     

The main part of the Elements.xml file can be referred to the Custom Action Section Id: it has name of the menu or other page elements where we want this feature to appear. Title: Title of the item to be shown on the site element Description: Description of the feature ImageUrl: The image should be present in the site in which the feature will be implemented. So it appends a Url of type “_layouts/images/abc.gif” UrlAction: is used to redirect users if they click on the link

7

SharePoint Features & Solutions   

       

      

The ElementManifest element is to point the feature to another xml file that contains CAML that defines various content depending upon its purposes including: Content Type Content Type Binding Control Custom Action Custom Action Group Document Converter Features Site Template Association Field Hide Custom Action List Instance List Template Module* Receivers User Migrator Workflow For example we want to use the Module tag . Then we will define it inside elements tag.

8

SharePoint Features & Solutions

Configuration of the Elements.xml File example:- Attributes are: Id: it has name of the menu or other page elements where we want this feature to appear. Title: Title of the item to be shown on the site element Description: Description of the feature We also have several elements as a part of this file. UrlAction is one such element that is used to redirect users if they click on the link.

9

SharePoint Features & Solutions Key classes associated with Features in SharePoint Object Model Structure. SPFeatureCollection/ SPFeature Refers to a feature state at a given site hierarchy level. SPFeatureProperty/ SPFeaturePropertyCollection We can access and modify the single property of a feature. SPFeatureScope As per the scope defined in the feature.xml file for example Farm, WebApplication, Site and Web. SPFeatureDefinition Name, scope, id, version in the Feature.xml file SPFeatureDependency Represents a feature upon which another feature depends. SPElementDefinition Represents a single element that will be provisioned when the feature is activated.

10

SharePoint Features & Solutions Enumerating the list of Features that are currently installed within a farm For this purpose you need to use an instance of the SPFarm class and access the feature definition property. To enumerate the list of active features on a given site you need to enumerate the Features property on the appropriate SPWeb or SPSite class instance. To create an instance of the SPFarm class you need to pass a connection string that points to firms configuration database. For Example:--

string dbConnection = @"server= 01HW164789\OFFICESERVERS; initial catalog=SharePoint_Config_313a1ef8-b61b-43cd-b289-408cce661437; Integrated Security=SSPI; "; SPFarm farm = SPFarm.Open(dbConnection); And the code goes like this…. 11

SharePoint Features & Solutions Activating/ Deactivating Features through Object Model SPSite site = new SPSite(@textBox1.Text); site.Features.Add(new Guid(textBox2.Text)); site.Features.Remove(new Guid(textBox3.Text)); Similar to the following stsadm command reference --Stsadm –o activatefeature -name [-url ] [-force] Stsadm –o deactivatefeature -name [-url ] [-force] Installing / Uninstalling Features SPSite site = new SPSite(@textBox1.Text); string dbConnection = @"server= 01HW164789\OFFICESERVERS; initial catalog=SharePoint_Config_313a1ef8-b61b-43cd-b289-408cce661437; Integrated Security=SSPI; "; SPFarm farm = SPFarm.Open(dbConnection); SPFeatureDefinitionCollection installedfeatures = farm.FeatureDefinitions; installedfeatures.Remove(new Guid(@textBox4.Text), true); Stsadm –o activatefeature -name [-url ] [-force] Stsadm –o deactivatefeature -name [-url ] [-force] 12

SharePoint Features & Solutions public class NewFeatureExample: SPFeatureReceiver { public override void FeatureActivated(SPFeatureReceiverProperties properties) { //throw new Exception("The method or operation is not implemented."); } public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { //throw new Exception("The method or operation is not implemented."); } public override void FeatureInstalled(SPFeatureReceiverProperties properties) { //throw new Exception("The method or operation is not implemented."); } public override void FeatureUninstalling(SPFeatureReceiverProperties properties) { //throw new Exception("The method or operation is not implemented."); } } This Methods get called as per the state of the feature. 13

SharePoint Features & Solutions     

Installfeature stsadm -o installfeature -filename -name [-force]



Filename - A valid file path, such as "MyFeature\Feature.xml“ Name – Name of the feature directory, such as “MyFeature” Force - Forces an installation of a feature that is already installed.



Uninstallfeature



stsadm -o uninstallfeature {-filename | -name | -id } [-force]



Activatefeature



stsadm.exe -o activatefeature {-filename | -name | -id } [-url ] [-force]



Deactivatefeature stsadm.exe -o deactivatefeature {-filename | -name | -id } [-url ] [-force]

 



14

SharePoint Features & Solutions 

The Command goes like this



stsadm InstallFeature -filename YourFeatureName\feature.xml –force



iisreset



To reflect the changes, it is necessary to restart the IIS.



Or,

 

You can simply create one batch file to execute the commands. Configuring Batch Scripts for the stsadm command lines



@SET DIR=”C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE”



@SET STSADM=”C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm”



Echo Copying filesxcopy /e /y TEMPLATE\* %DIR%



Echo Installing feature%STSADM% -o InstallFeature -filename YourFeatureName\feature.xml -force Echo Reatart IIS Worker Process





IISRESET

15

SharePoint Features & Solutions What is a Solution? A Solution is a package of SharePoint items for deployment - in physical terms it is a cabinet file (.cab) which is given the extension of .wsp to differentiate it from standard .cab files. Why Solutions?? 



 

The reason for this is that the Solution framework takes care of deploying all required files to all Web Front End (WFE) servers in a SharePoint farm. Features are generally deployed as part of the solution. Configuration of a solution package You must create a Manifest.xml file for your solution package.