1 / 34

Windows SharePoint Services: Custom Field Types

Contents. Custom Field Types Defined. Business Cases. Custom Field Types and Alternate WSS Extensibility. Custom Field Types Implementation. Discussion: SpsDev.Com's Filter Field is a custom field type that does filtering. Code walkthrough: Code walkthrough of phone number custom field type by Morga

cosmo
Download Presentation

Windows SharePoint Services: Custom Field Types

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


    1. Windows SharePoint Services: Custom Field Types Eugene Rosenfeld Black Blade Systems erosenfeld@blackbladesystems.com

    2. Contents Custom Field Types Defined Business Cases Custom Field Types and Alternate WSS Extensibility Custom Field Types Implementation Discussion: SpsDev.Coms Filter Field is a custom field type that does filtering Code walkthrough: Code walkthrough of phone number custom field type by Morgan Everett & Mark Collins Demo: Code walkthrough and demo of Todd Bleekers TechEd 2007 custom Virtual Earth field type Demo: Code walkthrough and demo of SharePoint SDK sample: How to create a custom field control Closeout 3 8 13 22 28 29 30 31 32

    3. Custom Field Types Defined Overview Custom field types are Windows SharePoint Services 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

    4. 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.

    5. 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.

    6. 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

    7. 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 Todd Bleekers Virtual Earth control uses custom properties to set the default value of the addresss State component Parameterize custom validation logic Target Audiences field type supports three custom properties that control the type of data a field instance will store (allow audiences, distribution lists, and SharePoint groups) Control rendering of field data Todd Bleekers Virtual Earth control uses custom properties to set the size of the Virtual Earth map 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

    8. Business Cases Overview Custom Data Storage Custom Data Validation Custom Field Rendering Custom Behavioral Logic

    9. 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

    10. 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

    11. 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)

    12. 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

    13. 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

    14. 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

    15. 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)

    16. 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

    17. 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

    18. 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

    19. 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

    20. Custom Field Types and Workflows Similarities between Custom Field Types and Workflows Both can execute custom code when list item data is changed

    21. 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

    22. Custom Field Types Implementation Overview Custom Field Type Definition Custom Field Type Properties Custom Field Data Validation Custom Field Value Classes Custom Field Type Deployment

    23. Custom Field Types Implementation Custom Field Type Definition A new fldtypes*.xml file 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 SPField class, more commonly, from another class that inherits from SPField, such as SPFieldMultiColumn The type defined by the FieldTypeClass attribute 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>

    24. 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. GetCustomProperty method Note: The SPField.Update method is not called when a new instance of a custom field type is added to a list. Only the SPField.OnAdded method gets called. Two ways to render the custom properties: Using the PropertySchema element 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>

    25. Custom Field Types Implementation Custom Field Data Validation Custom field types are validated by overriding the SPField. GetValidatedString method in the field class Throw the SPField.SPFieldValidationException exception when the supplied field value is not for the field

    26. 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. GetValidatedString method in the custom field class The default implementation calls the ValueClass.ToString method to get the string Convert a string field value back to a managed type Done by overriding the SPField. GetFieldValue method in the custom field class Value classes must be serializable, implementing the ToString method

    27. Custom Field Types Implementation Custom Field Type Deployment Fldtypes*.xml file must get copied to the "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\XML\ 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 any assemblies loaded from the GAC are un-cached and re-cached by the IIS worker process

    28. Discussion Discussion SpsDev.Coms Filter Field is a custom field type that does filtering http://www.SpsDev.Com

More Related