Features…What is a feature in Sharepoint 2007?

Download Report

Transcript Features…What is a feature in Sharepoint 2007?

SharePoint Development
101: Feature Design
By Becky Isserman
http://www.mosslover.com
SharePoint Development vs. ASP
.Net Development
• User Controls
• Features
DEMO
Build a User Control using the SharePoint Object Model
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
QUESTION: HOW MANY
FEATURES ARE INSTALLED
IN SHAREPOINT OUT OF
THE BOX?
Answer: 137
Feature Definition (feature.xml)
•
•
•
•
Includes:
Elements Attributes
Activation Dependencies
Feature Elements (included in
elements.xml files)
Element Attributes
Name
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
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?
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
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
Feature Elements (everything in
the element.xml files)
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
Feature Receivers
•
•
•
•
•
FeatureInstalled
FeatureUninstalling
FeatureActivated
FeatureDeactivating
Good Reference STSDEV Video with
Ted Pattison
DEMO
Create a Feature using STSDev
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
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)
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
Manual Installation and Activation
stsadm.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]
DEMO
Activation Areas & STSADM Demo
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
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
$$
Tools
• STSDev
– http://www.codeplex.com/stsdev
• VSEWSS 1.1 (Visual Studio Extensions for Windows
SharePoint Services)
– http://www.microsoft.com/downloads/details.aspx?FamilyI
D=3e1dcccd-1cca-433a-bb4d97b96bf7ab63&displaylang=en
• Andrew Connell CodeRush/Refactor Tool for
Developers
http://www.andrewconnell.com/blog/articles/Productivit
yToolsForSharePointDevelopers.aspx
• SharePoint for Developer's Part
1: http://msdn.microsoft.com/enus/rampup/dd221355.aspx
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
QUESTIONS? COMMENTS?
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