Eugene Rosenfeld: SharePoint Custom Field Types
Upcoming SlideShare
Loading in...5
×
 

Eugene Rosenfeld: SharePoint Custom Field Types

on

  • 4,024 views

 

Statistics

Views

Total Views
4,024
Views on SlideShare
4,024
Embed Views
0

Actions

Likes
0
Downloads
34
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Eugene Rosenfeld: SharePoint Custom Field Types Eugene Rosenfeld: SharePoint Custom Field Types Presentation Transcript

  • SharePoint Custom Field Types
    Eugene Rosenfeld
    CTO, Black Blade Associates
    2-time SharePoint MVP
    erosenfeld@blackbladeinc.com
    www.blackbladeinc.com
    thingsthatshouldbeeasy.blogspot.com
  • Contents
    Contents
    • Custom Field Types Defined
    • Business Cases
    • Custom Field Types and Alternate WSS Extensibility
    • Custom Field Types Implementation
    • Demo
  • Custom Field Types Defined
    Overview
    • Custom field types are Windows SharePoint Service’s mechanism for allowing developers to:
    • Define atomic data structures with custom data structures
    • Custom data validation
    • Custom rendering
    • Custom property storage and processing
    • These items are “what” custom field types can do
    • Custom field types can be thought of as a merging between fields, custom web parts, validators, and event receivers
  • Custom Field Types Defined
    Custom Field Type Scenarios
    • Custom field types allow developers to interact with and extend the way in which Windows SharePoint Services organizes, collects, modifies, stores, and displays list item data:
    • Add a field that is based on a custom field type to a list
    • Edit a list field that is based on a custom field type
    • Show data stored in a custom field type instance in the list item display form
    • Show data stored in a custom field type instance in the list item edit form
    • Show data stored in a custom field type instance in the list item new form
    • Show data stored in a custom field type instance in the list view
    • These items describe “when” we would resort to custom field types.
  • Custom Field Types Defined
    Custom Data Structures
    • Custom field types may define one or more field data components
    • SharePoint treats all field components as one, indivisible entity
    • SharePoint saves and loads all components of a custom field type as a single unit
    • Any custom data structure is fair game, as long as it is serializable as text
    • Why text, even for booleans, numbers, dates, etc?
    • All data is stored in SQL. Data is retrieved and modified using SQL statements. SQL statements are text, even for logically binary data.
  • Custom Field Types Defined
    Custom Rendering
    • Developers can associate web controls to display field data to users
    • Think of field render controls as custom web parts that are always associated with all instances of the custom field type
    • Custom rendering controls may include:
    • Web custom controls
    • Client controls or HTML
    • JavaScript
    • AJAX
    • Images
    • Anything else that can render a MIME type that the client browser can interpret
  • Custom Field Types Defined
    Custom Field Type Properties
    • Custom field types can define custom properties that instances of those field types can set
    • Custom field type properties are meant to allow users to modify the behavior of a custom field type instance
    • These properties can be used to:
    • Set default values for data stored in instance fields
    • Parameterize custom validation logic
    • Control rendering of field data
    • As with the field data, developers can define custom rendering and validation for custom field type properties
    • Custom field properties are very similar to custom web part properties
  • Business Cases
    Overview
    • Custom Data Storage
    • Custom Data Validation
    • Custom Field Rendering
    • Custom Behavioral Logic
  • Business Cases
    Custom Data Storage
    • Atomic multicolumn field
    • Address (street, city, state, zip)
    • Full name (first, middle, last)
    • Geo-data (latitude, longitude, elevation)
    • Pointer to external data
    • Primary key to an external database table
    • Parameter values to a Web Service call
    • URI to external records management system
  • Business Cases
    Custom Data Validation
    • Data is in a particular format
    • Email
    • SSN
    • Phone number
    • Product code
    • Guid
    • Related data from multiple controls is consistent
    • Address (street, city, state, zip)
    • Full name (first, middle, last)
    • Data is validated against an external entity
    • Database
    • XML file
    • Web Service – address is an actual valid street address
  • Business Cases
    Custom Field Rendering
    • Graphic
    • Chart
    • Map
    • KPI Indicator
    • Anti-bot / anti-OCR image
    • Embedded object
    • Flash
    • Silverlight
    • ActiveX
    • AJAX
    • Iframe
    • VML / SVG
    • User presence information (name with presence field)
  • Business Cases
    Custom Behavioral Logic
    • Typically used to control the behavior of the field when it is being populated with data
    • Accessing metadata stored on a system external to SharePoint
    • Custom dialog boxes
    • Wizard interfaces
    • Trees and other navigation elements
    • Asset picker control
  • Custom Field Types and Alternate WSS Extensibility
    Overview
    • Custom Field Types and Content Types
    • Custom Field Types and Custom Web Parts
    • Custom Field Types and Event Receivers
    • Custom Field Types and Workflows
  • Custom Field Types and Content Types
    Similarities between Custom Field Types and Content Types
    • Both can be used to define a grouping or set of discrete data
    • Both can trigger code execution when data changes
  • Custom Field Types and Content Types
    Deciding which One to Use
    • Use custom field types when:
    • Must be created by a developer
    • Must be defined using managed code (C#, VB.Net, etc)
    • Can complicate matters when writing code that consumes list field values that are custom field types
    • May prevent the use of third party tools or applications if these can not deal with custom field types
    • Use content types when:
    • Definable by content manager through the web UI
    • Deployable to SharePoint farm as XML (no code needed)
  • Custom Field Types and Custom Web Parts
    Similarities between Custom Field Types and Custom Web Parts
    • Both can define custom rendering for SharePoint data
    • Both can define custom metadata that alters the rendering of the data
    • Both can perform processing logic on their respective data
    • Both can access data outside of SharePoint
  • Custom Field Types and Custom Web Parts
    Deciding which One to Use
    • Use a custom field type when:
    • You want the custom defined rendering to always be associated with the field data
    • You want to define custom rendering that will be used in the listview web part when the field data is shown in the listview
    • You want to define custom rendering for field data that will be used in all instances of the display item, new item, and edit item forms for list items that contain the a field instance
    • Use a web part when:
    • You want to define custom rendering for a group of fields
    • You want to create views that aggregate information from multiple list items
    • You want to give users the ability to drag the custom rendering onto a web part page through a web browser
    • You want to participate in web part connections
  • Custom Field Types and Event Receivers
    Similarities between Custom Field Types and Event Receivers
    • Both can be used to run custom code when data in a list is about to change
    • Both can prevent changing list data from being saved to the content database
    • Both can be used to catch field schema changes on lists
  • Custom Field Types and Event Receivers
    Deciding which One to Use
    • Use a custom field type when:
    • You want the field code to run for every item an item is changed or added to every list with an instance of the field type exists
    • Note: Two field instances of a custom field type means the code runs twice!
    • Use an event receiver when:
    • You want to be able to activate or deactivate the code for all lists within a particular site (i.e. feature)
    • You need to work with data from several fields in the current list item
  • Custom Field Types and Workflows
    Similarities between Custom Field Types and Workflows
    • Both can execute custom code when list item data is changed
  • Custom Field Types and Workflows
    Deciding which One to Use
    • Use a custom field type when:
    • You want the field code to run for every item an item is changed or added to every list with an instance of the field type exists
    • Note: Two field instances of a custom field type means the code runs twice!
    • You want to execute code that finishes running quickly and stores no long-term state information (other than the actual list item field data)
    • Use a workflow when:
    • You want to allow users to be able to associate the code with specific list instances through a web browser
    • You want to give users the option to execute the code automatically or manually
    • Your code needs to run for a long time, over days, weeks, or months
    • You will need to collect information from users involved in the code execution through the browser
    • You need to work with data from several fields in the current list item
  • Custom Field Types Implementation
    Overview
    • Custom Field Type Definition
    • Custom Field Type Properties
    • Custom Field Data Validation
    • Custom Field Value Classes
    • Custom Field TypeDeployment
  • Custom Field Types Implementation
    Custom Field Type Definition
    • A new fldtypes*.xmlfile to hold your field type definition
    • This is the entry point that the WSS runtime uses to start addressing your custom field type
    • Similar in concept to the webtemp*.xml files for site definitions
    • A class the inherits from the SPFieldclass, more commonly, from another class that inherits from SPField, such as SPFieldMultiColumn
    • The type defined by the FieldTypeClassattribute must implement two constructors:
          public MyFieldComputed (SPFieldCollection fields, string fieldName)            : base(fields, fieldName){}
          public MyFieldComputed (SPFieldCollection fields, string typeName, string displayName)            : base(fields, typeName, displayName){}
    <FieldType>
    <Field Name="TypeName">MyComputed</Field>
    <Field Name="TypeDisplayName">$Resources:core,fldtype_computed;</Field>
    <Field Name="ParentType"> Computed </Field>
    <Field Name="FieldTypeClass">MySharePoint.MyFieldComputed</Field>
    <RenderPattern Name="PreviewDisplayPattern">
    <HTML><![CDATA[["]]></HTML><Property Select="DisplayName" HTMLEncode="TRUE"/><HTML>"$Resources:core,fldtypes011;</HTML>
    </RenderPattern>
    <RenderPattern Name="PreviewEditPattern"><Property Select="DisplayName" HTMLEncode="TRUE"/></RenderPattern>
    <RenderPattern Name="PreviewNewPattern"><Property Select="DisplayName" HTMLEncode="TRUE"/></RenderPattern>
    </FieldType>
  • Custom Field Types Implementation
    Custom Field Type Properties
    • Custom field properties are defined in a PropertySchema/Fields element
    • Each custom property is defined as a Field element
    • Custom field properties are available in code via the SPField. GetCustomPropertymethod
    Note: The SPField.Updatemethod is not called when a new instance of a custom field type is added to a list. Only the SPField.OnAddedmethod gets called.
    • Two ways to render the custom properties:
    • Using the PropertySchemaelement
    Note: There seems to be a bug in the PropertySchema element rendering system. The edit form for the list field does not bind the custom field property values to the form control correctly. Instead of binding the to the property values, the form binds to the property display names. The only known workaround is to use the next option.
    • Using a field editor user control
    <FieldType>
    <Field Name="TypeName">USAddress</Field>

    <PropertySchema>
    <Fields>
    <Field Name="DefaultState" DisplayName="Default State" MaxLength="2"
    DisplaySize="2" Type="Text">
    <Default>WA</Default>
    </Field>
    <Field Name="DefaultZip" DisplayName="Default Zip" MaxLength="5"
    DisplaySize="5" Type="Text">
    <Default>98052</Default>
    </Field>
    </Fields>
    </PropertySchema>
    </FieldType>
  • Custom Field Types Implementation
    Custom Field Data Validation
    • Custom field types are validated by overriding the SPField. GetValidatedStringmethod in the field class
    • Throw the SPField.SPFieldValidationExceptionexception when the supplied field value is not for the field
  • Custom Field Types Implementation
    Custom Field Value Classes
    • Custom field value classes do two primary tasks:
    • Convert field value as represented by managed types into a string
    • Done by overriding the SPField. GetValidatedStringmethod in the custom field class
    • The default implementation calls the ValueClass.ToStringmethod to get the string
    • Convert a string field valueback to a managed type
    • Done by overriding theSPField. GetFieldValuemethod in the custom field class
    • Value classes must be serializable, implementing the ToStringmethod
  • Custom Field Types Implementation
    Custom Field Type Deployment
    • Fldtypes*.xml file must get copied to the "%CommonProgramFiles%Microsoft Sharedweb server extensions12TEMPLATEXML“ directory
    • Assemblies that implement the custom field, custom field values, rendering controls must be deployed to the GAC
    • Any assemblies referenced by the custom field assemblies must also reside in the GAC
    • Requires an IIS application pool recycle or an IISRESET in order for changes to take affect.
    • The fldtype*.xml files are reparsed by the IIS worker process
    • The assemblies loaded from the GAC are un-cached and re-cached by the IIS worker process
  • Demo
    Demo
    Code walkthrough and demo of Media Field Type
    http://wsswmpcft.codeplex.com
  • Closeout
    Summary
    • Defining custom field types
    • Reviewing the business cases that justify creation of custom field types
    • Comparison between custom field types and other WSS extensibility
    • Code walkthrough and demo of several custom field type implementations
  • Closeout
    Additional Resources
    Black Blade Associates
    http://www.blackbladeinc.com
    “Things that should be Easy” by Eugene Rosenfeld
    http://thingsthatshouldbeeasy.blogspot.com/
    Phone number custom field type by Morgan Everett & Mark Collins
    http://www.sharethispoint.com/archive/2006/08/07/23.aspx#codetwo
    SharePoint SDK sample: How to create a custom field control
    http://msdn2.microsoft.com/en-us/library/aa981226.aspx
    SharePoint Server 2007 Visual How Tos
    http://msdn2.microsoft.com/en-us/library/bb530308.aspx
  • Closeout
    Questions?
  • Closeout
    Thank you sponsors!
    Closeout
    Thank you sponsors!
  • Closeout
    Remember to fill out evaluations for your chance to win cool prizes!
    2 ASUS Netbooks
    Also Some Books
    1 Typemock Isolator License
    A 2-5 Day Course from SetFocus on SharePoint
    Telerik RAD Controls Set
    1 DeliverPointWFE 2010 license (Worth $1500)
    1 BCS Meta Man license (Worth $1200)
    1 Lightning Conductor 2010 WFE license (Worth $800)
    1 Lightning Storm Forums license. (Worth $600)
    Closeout
    Remember to fill out evaluations for your chance to win cool prizes!
    3 Apple IPAD 32 GB Wifi