SharePoint Development 101: Feature Design

25
SharePoint Development 101: Feature Design By Becky Isserman http://www.mosslover.com

description

SharePoint Development 101: Feature Design. By Becky Isserman http://www.mosslover.com. SharePoint Development vs. ASP .Net Development. User Controls Features. Build a User Control using the SharePoint Object Model. Demo. What is a Feature?. - PowerPoint PPT Presentation

Transcript of SharePoint Development 101: Feature Design

Page 1: SharePoint Development 101: Feature Design

SharePoint Development 101: Feature Design

By Becky Isserman

http://www.mosslover.com

Page 2: SharePoint Development 101: Feature Design

SharePoint Development vs. ASP .Net Development

• User Controls

• Features

Page 3: SharePoint Development 101: Feature Design

DEMO

Build a User Control using the SharePoint Object Model

Page 4: SharePoint Development 101: Feature Design

What is a Feature?

• Re-usable solutions on the farm, web application, site collection (site), and site (web) level

• Have endless possibilities for use…

• Requires a Feature.xml (feature definition file)

• Can have an Elements.xml or more

• Are stored in 12\template\features

Page 5: SharePoint Development 101: Feature Design

QUESTION: HOW MANY FEATURES ARE INSTALLED IN SHAREPOINT OUT OF THE BOX?Answer: 137

Page 6: SharePoint Development 101: Feature Design

Feature Definition (feature.xml)

• Includes:

• Elements Attributes

• Activation Dependencies

• Feature Elements (included in elements.xml files)

Page 7: SharePoint Development 101: Feature Design

Element AttributesName Type Description Default Required

Scope Text Farm, Web Application, Site, Web None Yes

Id Text Guid, can be generated in GUIDGen.exe tool in Visual Studio 2005

None Yes

Title Text Title of feature None No

Description Text Description of feature None No

Hidden Boolean Ability for users to see feature False No

Version Text Version Number (i.e. 1.0.0.0) None No

ImageUrl Text Image for feature in activation area None No

ImageUrlAltText Text Alternate image text None No

Page 8: SharePoint Development 101: Feature Design

Feature Definition Example

<Feature Title = “My Feature”Scope = “Web”

Id=“235A5BAD-7D97-435C

A2DB-AB579CAD79BC”

Version = “2.3.1.2”

xmlns = “http://schemas.microsoft.com/sharepoint”>

<ElementManifests>

<ElementManifest Location=“Elements.xml” />

</ElementManifests>

</Feature>

Bonus: What do these attributes mean?

Page 9: SharePoint Development 101: Feature Design

Activation Dependencies

• Definition: Requirement in the relationship between two features

• Can be on the same scope or cross-scope– Between two separate scope– i.e. Web to Site, Site to Web Application, or

Web Application to Farm

• Used to guarantee resources or group features together

Page 10: SharePoint Development 101: Feature Design

THE TEAM COLLABORATION SITE DEFINITION ACTIVATES 19 FEATURES CAN YOU NAME SOME OF THEM?AnnouncementsList GanttTasksList TasksList

ContactsList GridList WebPageLibrary

CustomList IssuesList WorkflowProcessLibrary

DataSourceLibrary LinksList WorkflowHistoryList

DiscussionsList NoCodeWorkflowLibrary XmlFormLibrary

DocumentLibrary PictureLibrary

EventsList SurveysList

Page 11: SharePoint Development 101: Feature Design

Feature Elements (everything in the element.xml files)

Page 12: SharePoint Development 101: Feature Design

Name Scope Description

Content Type Site Defines a custom content type when activated (templates, etc.)

Content Type Binding Site Can define a content type included in the onet.xml

Control All Can replace any ascx control (i.e. search controls, etc…)

Custom Action All Can add various actions (toolbar, menu, site settings…)

Custom Action Group All Group of custom actions

Document Convertor Farm, Web App Site

Converts a document to a copy of itself in a different file format

Feature/Site Template Association

Farm, Web App, Site

Binds features with a site definition, so all sites with that definition use the feature when created (most of the Fantastic 40 use this element)

Field Site Creates a site column for use in any list

List Instance Site, Web Creates a list of the type defined

List Template Site, Web Allows the use of a custom list template

Module Site, Web List of files to support the feature

Receiver All Registers an event receiver for an item

Workflow Site Contains the definition for a workflow

Page 13: SharePoint Development 101: Feature Design

Feature Receivers

• FeatureInstalled

• FeatureUninstalling

• FeatureActivated

• FeatureDeactivating

• Good Reference STSDEV Video with Ted Pattison

Page 14: SharePoint Development 101: Feature Design

DEMO

Create a Feature using STSDev

Page 15: SharePoint Development 101: Feature Design

Solution Package

• Feature.xml and Elements.xml files• Manifest.xml

– GUID– Tells feature if it should be deployed on WFE’s, Application

Server, etc…– Lists Safe Controls

• Diamond Directive File (ddf)– Place to include files and directories for solution package– .Set DestinationDir=Directory

• To manually create Feature Package (wsp file):MakeCab.exe /F DeploymentFiles\Test.ddf /D CabinetNameTemplate=Feature.wsp /D DiskDirectory1=wsp

Page 16: SharePoint Development 101: Feature Design

Solution Package

• Dynamically create a feature package by creating Test.targets file– Add some xml to point to MakeCab.exe and add command shell– Right click on the solution in Solution Explorer and select

“Unload Project”– Right click the project name in solution explorer and select Edit

[project name].csproj– Add to end: <Import Project = “DeploymentFiles\Test.targets” />– Delete all commented xml, but <Target

Name=“AfterBuild”></Target>– Add:

<Target Name = “AfterBuild”><CallTarget Targets = “Test” /></Target>

– Save Changes and Right Click on the project name and choose “Load” (you may see a warning dialog box, ignore it)

Page 17: SharePoint Development 101: Feature Design

Manual Installation and Activation

• All Features must be installed before they can be activated

• All features must be deactivated before they can be uninstalled, unless scope is farm or web app

Page 18: SharePoint Development 101: Feature Design

Manual Installation and Activationstsadm.exe –o installfeature

{-filename <relative path to Feature.xml> |

-name <feature folder>}

[-force]

stsadm.exe –o uninstallfeature

{-filename <relative path to Feature.xml> |

-name <feature folder> |

-id <feature Id>}

[-force]

stsadm.exe –o activatefeature

{-filename <relative path to Feature.xml> |

-id <feature id>}

[-url <url>]

[-force]

stsadm.exe –o deactivatefeature

{-filename <relative path to Feature.xml> |

-id <feature id>}

[-url <url>]

[-force]

Page 19: SharePoint Development 101: Feature Design

DEMO

Activation Areas & STSADM Demo

Page 20: SharePoint Development 101: Feature Design

Feature Disadvantages

• Before STSDev you had to manually create the manifest, ddf files, feature.xml, elements.xml, solution installer, etc…

• Deactivating and retracting features leave artifacts– Not all lists, content types, and columns leave

when the feature is turned off– Can still remove items manually

• Some people do not like coding only in xml– XML intellisense was just added in the new

SDK for SharePoint• There is no debugger• There is no pretty design interface

Page 21: SharePoint Development 101: Feature Design

Feature Advantages

• Easy to deploy in multiple environments and sites

• Creates items as un-customized– i.e. master pages can reside in one place and

include 3 references, rather than normally where SharePoint Designer creates 3 separate master pages

• Can control site columns and content types– Harder to track if created individually in user

interface• Overall a lot of time is saved, which equals $

$

Page 22: SharePoint Development 101: Feature Design

Tools

• STSDev– http://www.codeplex.com/stsdev

• VSEWSS 1.1 (Visual Studio Extensions for Windows SharePoint Services)– http://www.microsoft.com/downloads/details.aspx?

FamilyID=3e1dcccd-1cca-433a-bb4d-97b96bf7ab63&displaylang=en

• Andrew Connell CodeRush/Refactor Tool for Developershttp://www.andrewconnell.com/blog/articles/ProductivityToolsForSharePointDevelopers.aspx

• SharePoint for Developer's Part 1: http://msdn.microsoft.com/en-us/rampup/dd221355.aspx

Page 23: SharePoint Development 101: Feature Design

References

• Professional SharePoint 2007 Development by John Holliday, et al. pages 138-158

• Microsoft SharePoint Server 2007 Bible by Wynne Leon, et al. pages 255-283

• Real World SharePoint 2007 b Scot Hillier, et al. pages 96-111

• Professional SharePoint 2007 Web Content Management Development by Andrew Connell pages 63-67

Page 24: SharePoint Development 101: Feature Design

QUESTIONS? COMMENTS?

Page 25: SharePoint Development 101: Feature Design

Contact Information

• Blog: http://www.mosslover.com

• E-Mail: [email protected]

• SharePoint Comic: http://www.sharepointcomic.com

• Kansas City Office Geeks Site: http://www.officegeeks.org/kcog