Your SlideShare is downloading. ×
0
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Eugene Rosenfeld: SharePoint Custom Field Types
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Eugene Rosenfeld: SharePoint Custom Field Types

3,322

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
3,322
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
35
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. SharePoint Custom Field Types<br />Eugene Rosenfeld<br />CTO, Black Blade Associates<br />2-time SharePoint MVP<br />erosenfeld@blackbladeinc.com<br />www.blackbladeinc.com<br />thingsthatshouldbeeasy.blogspot.com<br />
  • 2. Contents<br />Contents<br /><ul><li>Custom Field Types Defined
  • 3. Business Cases
  • 4. Custom Field Types and Alternate WSS Extensibility
  • 5. Custom Field Types Implementation
  • 6. Demo</li></li></ul><li>Custom Field Types Defined<br />Overview<br /><ul><li>Custom field types are Windows SharePoint Service’s mechanism for allowing developers to:
  • 7. Define atomic data structures with custom data structures
  • 8. Custom data validation
  • 9. Custom rendering
  • 10. Custom property storage and processing
  • 11. These items are “what” custom field types can do
  • 12. Custom field types can be thought of as a merging between fields, custom web parts, validators, and event receivers</li></li></ul><li>Custom Field Types Defined<br />Custom Field Type Scenarios<br /><ul><li>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:
  • 13. Add a field that is based on a custom field type to a list
  • 14. Edit a list field that is based on a custom field type
  • 15. Show data stored in a custom field type instance in the list item display form
  • 16. Show data stored in a custom field type instance in the list item edit form
  • 17. Show data stored in a custom field type instance in the list item new form
  • 18. Show data stored in a custom field type instance in the list view
  • 19. These items describe “when” we would resort to custom field types.</li></li></ul><li>Custom Field Types Defined<br />Custom Data Structures <br /><ul><li>Custom field types may define one or more field data components
  • 20. SharePoint treats all field components as one, indivisible entity
  • 21. SharePoint saves and loads all components of a custom field type as a single unit
  • 22. Any custom data structure is fair game, as long as it is serializable as text
  • 23. Why text, even for booleans, numbers, dates, etc?
  • 24. All data is stored in SQL. Data is retrieved and modified using SQL statements. SQL statements are text, even for logically binary data.</li></li></ul><li>Custom Field Types Defined<br />Custom Rendering<br /><ul><li>Developers can associate web controls to display field data to users
  • 25. Think of field render controls as custom web parts that are always associated with all instances of the custom field type
  • 26. Custom rendering controls may include:
  • 27. Web custom controls
  • 28. Client controls or HTML
  • 29. JavaScript
  • 30. AJAX
  • 31. Images
  • 32. Anything else that can render a MIME type that the client browser can interpret</li></li></ul><li>Custom Field Types Defined<br />Custom Field Type Properties<br /><ul><li>Custom field types can define custom properties that instances of those field types can set
  • 33. Custom field type properties are meant to allow users to modify the behavior of a custom field type instance
  • 34. These properties can be used to:
  • 35. Set default values for data stored in instance fields
  • 36. Parameterize custom validation logic
  • 37. Control rendering of field data
  • 38. As with the field data, developers can define custom rendering and validation for custom field type properties
  • 39. Custom field properties are very similar to custom web part properties</li></li></ul><li>Business Cases<br />Overview<br /><ul><li>Custom Data Storage
  • 40. Custom Data Validation
  • 41. Custom Field Rendering
  • 42. Custom Behavioral Logic</li></li></ul><li>Business Cases<br />Custom Data Storage<br /><ul><li>Atomic multicolumn field
  • 43. Address (street, city, state, zip)
  • 44. Full name (first, middle, last)
  • 45. Geo-data (latitude, longitude, elevation)
  • 46. Pointer to external data
  • 47. Primary key to an external database table
  • 48. Parameter values to a Web Service call
  • 49. URI to external records management system</li></li></ul><li>Business Cases<br />Custom Data Validation<br /><ul><li>Data is in a particular format
  • 50. Email
  • 51. SSN
  • 52. Phone number
  • 53. Product code
  • 54. Guid
  • 55. Related data from multiple controls is consistent
  • 56. Address (street, city, state, zip)
  • 57. Full name (first, middle, last)
  • 58. Data is validated against an external entity
  • 59. Database
  • 60. XML file
  • 61. Web Service – address is an actual valid street address</li></li></ul><li>Business Cases<br />Custom Field Rendering<br /><ul><li>Graphic
  • 62. Chart
  • 63. Map
  • 64. KPI Indicator
  • 65. Anti-bot / anti-OCR image
  • 66. Embedded object
  • 67. Flash
  • 68. Silverlight
  • 69. ActiveX
  • 70. AJAX
  • 71. Iframe
  • 72. VML / SVG
  • 73. User presence information (name with presence field)</li></li></ul><li>Business Cases<br />Custom Behavioral Logic<br /><ul><li>Typically used to control the behavior of the field when it is being populated with data
  • 74. Accessing metadata stored on a system external to SharePoint
  • 75. Custom dialog boxes
  • 76. Wizard interfaces
  • 77. Trees and other navigation elements
  • 78. Asset picker control</li></li></ul><li>Custom Field Types and Alternate WSS Extensibility<br />Overview<br /><ul><li>Custom Field Types and Content Types
  • 79. Custom Field Types and Custom Web Parts
  • 80. Custom Field Types and Event Receivers
  • 81. Custom Field Types and Workflows</li></li></ul><li>Custom Field Types and Content Types<br />Similarities between Custom Field Types and Content Types<br /><ul><li>Both can be used to define a grouping or set of discrete data
  • 82. Both can trigger code execution when data changes</li></li></ul><li>Custom Field Types and Content Types<br />Deciding which One to Use<br /><ul><li>Use custom field types when:
  • 83. Must be created by a developer
  • 84. Must be defined using managed code (C#, VB.Net, etc)
  • 85. Can complicate matters when writing code that consumes list field values that are custom field types
  • 86. May prevent the use of third party tools or applications if these can not deal with custom field types
  • 87. Use content types when:
  • 88. Definable by content manager through the web UI
  • 89. Deployable to SharePoint farm as XML (no code needed)</li></li></ul><li>Custom Field Types and Custom Web Parts<br />Similarities between Custom Field Types and Custom Web Parts<br /><ul><li>Both can define custom rendering for SharePoint data
  • 90. Both can define custom metadata that alters the rendering of the data
  • 91. Both can perform processing logic on their respective data
  • 92. Both can access data outside of SharePoint </li></li></ul><li>Custom Field Types and Custom Web Parts<br />Deciding which One to Use<br /><ul><li>Use a custom field type when:
  • 93. You want the custom defined rendering to always be associated with the field data
  • 94. You want to define custom rendering that will be used in the listview web part when the field data is shown in the listview
  • 95. 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
  • 96. Use a web part when:
  • 97. You want to define custom rendering for a group of fields
  • 98. You want to create views that aggregate information from multiple list items
  • 99. You want to give users the ability to drag the custom rendering onto a web part page through a web browser
  • 100. You want to participate in web part connections</li></li></ul><li>Custom Field Types and Event Receivers<br />Similarities between Custom Field Types and Event Receivers<br /><ul><li>Both can be used to run custom code when data in a list is about to change
  • 101. Both can prevent changing list data from being saved to the content database
  • 102. Both can be used to catch field schema changes on lists</li></li></ul><li>Custom Field Types and Event Receivers<br />Deciding which One to Use<br /><ul><li>Use a custom field type when:
  • 103. 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
  • 104. Note: Two field instances of a custom field type means the code runs twice!
  • 105. Use an event receiver when:
  • 106. You want to be able to activate or deactivate the code for all lists within a particular site (i.e. feature)
  • 107. You need to work with data from several fields in the current list item</li></li></ul><li>Custom Field Types and Workflows<br />Similarities between Custom Field Types and Workflows<br /><ul><li>Both can execute custom code when list item data is changed</li></li></ul><li>Custom Field Types and Workflows<br />Deciding which One to Use<br /><ul><li>Use a custom field type when:
  • 108. 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
  • 109. Note: Two field instances of a custom field type means the code runs twice!
  • 110. You want to execute code that finishes running quickly and stores no long-term state information (other than the actual list item field data)
  • 111. Use a workflow when:
  • 112. You want to allow users to be able to associate the code with specific list instances through a web browser
  • 113. You want to give users the option to execute the code automatically or manually
  • 114. Your code needs to run for a long time, over days, weeks, or months
  • 115. You will need to collect information from users involved in the code execution through the browser
  • 116. You need to work with data from several fields in the current list item</li></li></ul><li>Custom Field Types Implementation<br />Overview<br /><ul><li>Custom Field Type Definition
  • 117. Custom Field Type Properties
  • 118. Custom Field Data Validation
  • 119. Custom Field Value Classes
  • 120. Custom Field TypeDeployment</li></li></ul><li>Custom Field Types Implementation<br />Custom Field Type Definition<br /><ul><li>A new fldtypes*.xmlfile to hold your field type definition
  • 121. This is the entry point that the WSS runtime uses to start addressing your custom field type
  • 122. Similar in concept to the webtemp*.xml files for site definitions
  • 123. A class the inherits from the SPFieldclass, more commonly, from another class that inherits from SPField, such as SPFieldMultiColumn
  • 124. The type defined by the FieldTypeClassattribute must implement two constructors:</li></ul>      public MyFieldComputed (SPFieldCollection fields, string fieldName)            : base(fields, fieldName){}<br />      public MyFieldComputed (SPFieldCollection fields, string typeName, string displayName)            : base(fields, typeName, displayName){}<br /> <FieldType><br /> <Field Name="TypeName">MyComputed</Field><br /> <Field Name="TypeDisplayName">$Resources:core,fldtype_computed;</Field><br /> <Field Name="ParentType"> Computed </Field><br /> <Field Name="FieldTypeClass">MySharePoint.MyFieldComputed</Field> <br /><RenderPattern Name="PreviewDisplayPattern"><br /> <HTML><![CDATA[["]]></HTML><Property Select="DisplayName" HTMLEncode="TRUE"/><HTML>"$Resources:core,fldtypes011;</HTML><br /> </RenderPattern><br /> <RenderPattern Name="PreviewEditPattern"><Property Select="DisplayName" HTMLEncode="TRUE"/></RenderPattern><br /> <RenderPattern Name="PreviewNewPattern"><Property Select="DisplayName" HTMLEncode="TRUE"/></RenderPattern> <br /> </FieldType><br />
  • 125. Custom Field Types Implementation<br />Custom Field Type Properties<br /><ul><li>Custom field properties are defined in a PropertySchema/Fields element
  • 126. Each custom property is defined as a Field element
  • 127. Custom field properties are available in code via the SPField. GetCustomPropertymethod</li></ul>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.<br /><ul><li>Two ways to render the custom properties:
  • 128. Using the PropertySchemaelement</li></ul>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.<br /><ul><li>Using a field editor user control</li></ul><FieldType><br /> <Field Name="TypeName">USAddress</Field><br /> …<br /> <PropertySchema><br /> <Fields><br /> <Field Name="DefaultState" DisplayName="Default State" MaxLength="2" <br />DisplaySize="2" Type="Text"><br /> <Default>WA</Default><br /> </Field><br /> <Field Name="DefaultZip" DisplayName="Default Zip" MaxLength="5" <br />DisplaySize="5" Type="Text"><br /> <Default>98052</Default><br /> </Field><br /> </Fields><br /> </PropertySchema><br /></FieldType><br />
  • 129. Custom Field Types Implementation<br />Custom Field Data Validation<br /><ul><li>Custom field types are validated by overriding the SPField. GetValidatedStringmethod in the field class
  • 130. Throw the SPField.SPFieldValidationExceptionexception when the supplied field value is not for the field</li></li></ul><li>Custom Field Types Implementation<br />Custom Field Value Classes<br /><ul><li>Custom field value classes do two primary tasks:
  • 131. Convert field value as represented by managed types into a string
  • 132. Done by overriding the SPField. GetValidatedStringmethod in the custom field class
  • 133. The default implementation calls the ValueClass.ToStringmethod to get the string
  • 134. Convert a string field valueback to a managed type
  • 135. Done by overriding theSPField. GetFieldValuemethod in the custom field class
  • 136. Value classes must be serializable, implementing the ToStringmethod</li></li></ul><li>Custom Field Types Implementation<br />Custom Field Type Deployment<br /><ul><li>Fldtypes*.xml file must get copied to the "%CommonProgramFiles%Microsoft Sharedweb server extensions12TEMPLATEXML“ directory
  • 137. Assemblies that implement the custom field, custom field values, rendering controls must be deployed to the GAC
  • 138. Any assemblies referenced by the custom field assemblies must also reside in the GAC
  • 139. Requires an IIS application pool recycle or an IISRESET in order for changes to take affect.
  • 140. The fldtype*.xml files are reparsed by the IIS worker process
  • 141. The assemblies loaded from the GAC are un-cached and re-cached by the IIS worker process</li></li></ul><li>Demo<br />Demo<br />Code walkthrough and demo of Media Field Type<br />http://wsswmpcft.codeplex.com<br />
  • 142. Closeout<br />Summary<br /><ul><li>Defining custom field types
  • 143. Reviewing the business cases that justify creation of custom field types
  • 144. Comparison between custom field types and other WSS extensibility
  • 145. Code walkthrough and demo of several custom field type implementations</li></li></ul><li>Closeout<br />Additional Resources<br />Black Blade Associates<br />http://www.blackbladeinc.com<br />“Things that should be Easy” by Eugene Rosenfeld<br />http://thingsthatshouldbeeasy.blogspot.com/<br />Phone number custom field type by Morgan Everett & Mark Collins<br />http://www.sharethispoint.com/archive/2006/08/07/23.aspx#codetwo<br />SharePoint SDK sample: How to create a custom field control<br />http://msdn2.microsoft.com/en-us/library/aa981226.aspx<br />SharePoint Server 2007 Visual How Tos<br />http://msdn2.microsoft.com/en-us/library/bb530308.aspx<br />
  • 146. Closeout<br />Questions?<br />
  • 147. Closeout<br />Thank you sponsors!<br />Closeout<br />Thank you sponsors!<br />
  • 148. Closeout<br />Remember to fill out evaluations for your chance to win cool prizes!<br />2 ASUS Netbooks<br />Also Some Books<br />1 Typemock Isolator License<br />A 2-5 Day Course from SetFocus on SharePoint<br />Telerik RAD Controls Set<br />1 DeliverPointWFE 2010 license (Worth $1500)<br />1 BCS Meta Man license (Worth $1200)<br />1 Lightning Conductor 2010 WFE license (Worth $800)<br />1 Lightning Storm Forums license. (Worth $600)<br />Closeout<br />Remember to fill out evaluations for your chance to win cool prizes!<br />3 Apple IPAD 32 GB Wifi<br />

×