<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>SharePoint Magazine &#187; usx</title>
	<atom:link href="http://sharepointmagazine.net/tag/usx/feed" rel="self" type="application/rss+xml" />
	<link>http://sharepointmagazine.net</link>
	<description>SharePoint Magazine is an online Magazine dedicated to the world of SharePoint</description>
	<lastBuildDate>Mon, 05 Jul 2010 09:14:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Customizing the User Experience of SharePoint: Custom fields deep dive (Part 5 of 6)</title>
		<link>http://sharepointmagazine.net/technical/development/customizing-the-user-experience-of-sharepoint-custom-fields-deep-dive-part-5-of-6</link>
		<comments>http://sharepointmagazine.net/technical/development/customizing-the-user-experience-of-sharepoint-custom-fields-deep-dive-part-5-of-6#comments</comments>
		<pubDate>Wed, 25 Feb 2009 07:12:58 +0000</pubDate>
		<dc:creator>furuknap</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[CAML]]></category>
		<category><![CDATA[column]]></category>
		<category><![CDATA[experiance]]></category>
		<category><![CDATA[field]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[site]]></category>
		<category><![CDATA[type]]></category>
		<category><![CDATA[User]]></category>
		<category><![CDATA[usx]]></category>

		<guid isPermaLink="false">http://sharepointmagazine.net/?p=2742</guid>
		<description><![CDATA[The Customizing the User Experience of SharePoint series aims to explain how the user experience works, from how the interface is built down to details on how columns of lists  get created.]]></description>
			<content:encoded><![CDATA[<p>Part 5 of the “Customizing the User Experience of SharePoint” series. This day we also celebrate the third day of SharePoint User Experience week here on <a href="http://sharepointmagazine.net/" target="_blank">SharePoint Magazine</a>. One full week, focusing only on understanding SharePoint architecture from a user experience point of view. If it could be any better it would have to be covered in chocolate.</p>
<p>The Customizing the User Experience of SharePoint series aims to explain how the user experience works, from how the interface is built down to details on how columns of lists  get created.</p>
<p>The series is also an exclusive preview of the topics from my upcoming book, “<a title="SharePoint Developer book" href="http://www.understandingsharepoint.com/userexperience" target="_blank">Building the SharePoint User Experience</a>”, which deals with SharePoint user experience for 350 pages. Actually, as with this series, the book explains the SharePoint architecture from a user experience perspective.</p>
<p>Here is an article outline for the six parts:</p>
<p><strong>Part 1: Overview of the default SharePoint interface from a technical point of view</strong></p>
<p>In the first article we will look at how the default SharePoint interface is built. We will look at a site, going from top-down, explore some of the the default lists, the fields used to create the basic field types, which content types are available, and how list forms are rendered.</p>
<p><strong>Part 2: Modifying the default experience </strong></p>
<p>This article will show you which options are available for you to modify and improve the default setup. Learn how to override the default rendering of fields or forms without voiding your supported state.</p>
<p><strong>Part 3: Lists and custom list forms </strong></p>
<p>The third article will cover the basics of customizing lists using different views, custom list forms, and fields.</p>
<p><strong>Part 4: Content types user interface</strong></p>
<p>The next article will explore how you can utilize content types to display different input forms and display forms.</p>
<p><strong>Part 5: Custom fields deep dive </strong></p>
<p>Ever wanted to create a new field type? SharePoint enables you to do this and it is a very powerful tool for customizing the user experience.</p>
<p><strong>Part 6: Fast track to feature generation </strong></p>
<p>Writing custom lists with content types by hand can take a massive amount of time. In the final installment I will share with you some tools and techniques that makes list, field, and content type generation very fast.</p>
<p>Don’t fear if you think the previous parts have contain too little code, however, for this time we are creating custom field types. But first, we need to understand how columns work in SharePoint</p>
<h1>Columns or fields?</h1>
<p>Before we go any further I’d like to clarify the use of the names fields, field types, and columns.</p>
<p>In most cases columns and fields refer to the same thing, namely the names of the individual items we use to store data in a SharePoint list item. The confusion may come from the use of the name Column in the web interface and the name Field in code. when you go to add a new column/field to a list or a content type the term ‘column’ is used, but when you write a feature to deploy a new site column or a content type that has columns you suddenly use the name Field.</p>
<p>To confuse even further there’s the concept of field types. Field types are types of data. Compare this to SQL you may think of nvarchar, bigint, and datetime. However, field types are more complex as they also include the visual rendering of the data, both for input and display.</p>
<p>To make sure we are clear in this article I’ll use the name Column and not Field while referring to the columns of a list.</p>
<h1>Site columns and list columns</h1>
<p>You can define columns on two levels, either on the site level or on the list level. Site columns are useful if you intend to use a column in multiple lists. Rather than having to define all the settings for every list, you can define a site column with all the settings and add that site column to the lists.</p>
<p>Site columns are your only option if you intend to use your columns in content types. List columns are available only for a particular list. For lists, you can use either site columns or list columns. Or, actually, you can use list columns only. Or, actually, you can add site columns, but they become list columns. Oh, I know this may be confusing. Let me explain.</p>
<p>On the list or library settings page, you have the option to either create a new column or add an existing site column. If you choose the latter, a copy of the site column is made using the same field ID as the site column. The copy becomes a list column.</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/sitetolistcolumn.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/sitetolistcolumn-thumb.png" border="0" alt="SiteToListColumn" width="829" height="868" /></a></p>
<p>The use of similar ID values for both the site column and the list column maintains the parent-child relationship. This relationship means you can make changes to the site column and optionally have all child columns inherit those changes.</p>
<p>This is a good thing, because it means that the list column is detached from the site column when you want it to be, but it can still maintain its relationship to the parent site column. An example might clarify this.</p>
<p>Let’s say you have a site column named Recipient used to store who will receive reports from different departments. You add that field to a new list for a new department, but then the department head comes to you and says that the column needs to be named “Target manager” instead.</p>
<p>In this situation, you can simply go to the list settings and change the name of the column on that list. Had you changed the site columns, every occurrence of the Recipient column would be changed, and other departments might not like that.</p>
<h2>Site Columns in Content Types</h2>
<p>What might spin your head a bit later is when we start to consider how content types work in this scenario. As I mentioned in the previous part of the series, content types use only site columns, so if we want to change a column for a content type on a list, we might be in trouble. And, if content types are so cool and we should use them as often as we can, how can we have such a limitation?</p>
<p>The answer is that content types also create list column copies of their respective site columns. When you add a content type to a list or library, all the site columns of that content type are copied into list columns on a list.</p>
<p>Problem solved.</p>
<h1>Site Columns in CAML</h1>
<p>To add site columns using the web interface, you simply go to the site where you want to column, then go to the Site Settings page and finally select the site columns. Create your site column by clicking Create, fill in the form, submit it, and live happily ever after. You can do this on any site.</p>
<p>Creating a basic field using a feature is slightly more complex, but not much. First, create a new feature, and make sure your feature scope is set to site, not web. With <a href="http://www.codeplex.com/wspbuilder" target="_blank">WSPBuilder</a>, this is as easy as creating a new WSPBuilder project and adding a new item of the Blank Feature. You’ll learn plenty more about WSPBuilder in the next part of this series.</p>
<p>As with content types, site column features are site scoped, and of course you remember that site in this feature context means site collection. The ID of the field needs to be unique to the entire site collection to support content type inheritance and to allow site columns to be used in child sites.</p>
<p>Yes, that’s correct. Columns have scope just like content types. If you define a site column in one site, all child sites will also be able to use that column. Site columns and content types are closely connected.</p>
<p>Let’s get back to your feature.  now—In your elements file, add a Field element as such:<br />
&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243; ?&gt;<br />
&lt;Elements xmlns=&#8221;<a href="http://schemas.microsoft.com/sharepoint/&quot;">http://schemas.microsoft.com/sharepoint/&#8221;</a>&gt;<br />
&lt;Field Name=&#8221;Recipient&#8221; DisplayName=&#8221;Recipient&#8221;<br />
ID=&#8221;{053EC00E-D451-4733-8CA0-31532C974E91}&#8221; Type=&#8221;Text&#8221; &gt;<br />
&lt;/Field&gt;<br />
&lt;/Elements&gt;</p>
<p>Now, before you take even a sip of your coffee or even draw another breath, pay very close attention to the following: Unlike other GUID examples, you <strong>must</strong> use brackets in the GUID ID value when defining site columns. Do not forget this.</p>
<p>When you build and deploy your new feature, and of course remember to activate from the Site Collection Features page you should see your new site column on the Site Columns page. This also means that your site column is now ready to use in any content type or list as you see fit.</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/sitecolumndeployed.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/sitecolumndeployed-thumb.png" border="0" alt="SiteColumnDeployed" width="558" height="268" /></a></p>
<p>To limit the scope and ask you to notice the Type which is Text as this is important to our next step when we look at field types.</p>
<h1>Field Types</h1>
<p>Columns in SharePoint may be analogous to columns in a SQL table. If so, field types are analogous to the data types in SQL such as ntext, bigint, datetime, and bit. Actually, the correct way of thinking this is that a field type value is approximately the same as a SQL data type, while the field type itself is a bit more complex. Bear with me a second if you’re confused, I’ll try to clear things up a bit.</p>
<p>A SharePoint field type comprises several elements that handle the storage and the rendering of the field type. The easiest thing is to break these elements into three classes:</p>
<p><strong>Field Type</strong></p>
<p>This is the code element, defined as a .NET class, which ties together the value and visual representation of the field.</p>
<p><strong>Field Type Control</strong></p>
<p>This element is responsible for the visual rendering of the field, also a .NET class, and with an optional ASCX user control to render the output.</p>
<p><strong>Field Type Value</strong></p>
<p>Finally, the field type value handles storage of the data in columns based on the field type, again, this is a .NET class. For simple string values this class is optional.</p>
<p>When you first start to look at custom field types you may be very confused from how these elements interact, but once you start looking at what happens in each element, everything clears up a lot. We will get to that in a moment.</p>
<p>In addition to the three elements defined above you also have a Field Type Definition. This is really the simplest element as it is a plain XML file that only describes the field type to SharePoint. These field type definitions are stored in the [12]\TEMPLATE\XML folder inside files that are named fldtypes_XXXXXX.xml, where XXXXXX is an arbitrary string. The built-in field types are stored in the file called fldtypes.xml.</p>
<p>Let’s start out with this field type definition and work our way from there.</p>
<p>Before we being, however, note that field types are not deployed as features. Field types are global to the farm and as such should be deployed as a solution.</p>
<h2>Building your first custom field type</h2>
<p>Start by creating a new WSPBuilder project. You have <a href="http://www.codeplex.com/wspbuilder" target="_blank">WSPBuilder</a>, right? Call it whatever you like, I’ve called mine SPMType. WSPBulder automatically creates a signing key and sets up your project to be signed.</p>
<p>Next, add a TEMPLATE folder under the 12 folder, and then an XML folder under the TEMPLATE folder.</p>
<p>Inside the XML folder, add a new XML file, called ‘fldtypes_SPMType.xml’. Or, choose another name, as long as you adhere to the fldtypes_XXXXXX.xml format.</p>
<p>Your solution explorer should now look like this:</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/solutionexplorerstart.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/solutionexplorerstart-thumb.png" border="0" alt="SolutionExplorerStart" width="277" height="209" /></a></p>
<h3>Field Type Definition</h3>
<p>Open the fldtypes_SPMType.xml file and add the following XML code. I’ll explain each element afterwards:</p>
<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243; ?&gt;<br />
&lt;FieldTypes&gt;<br />
&lt;FieldType&gt;<br />
&lt;Field Name=&#8221;TypeName&#8221;&gt;SPMType&lt;/Field&gt;<br />
&lt;Field Name=&#8221;ParentType&#8221;&gt;Text&lt;/Field&gt;<br />
&lt;Field Name=&#8221;TypeDisplayName&#8221;&gt;SPMType&lt;/Field&gt;<br />
&lt;Field Name=&#8221;TypeShortDescription&#8221;&gt;Description for SPMType&lt;/Field&gt;<br />
&lt;Field Name=&#8221;UserCreatable&#8221;&gt;TRUE&lt;/Field&gt;<br />
&lt;Field Name=&#8221;Sortable&#8221;&gt;TRUE&lt;/Field&gt;<br />
&lt;Field Name=&#8221;AllowBaseTypeRendering&#8221;&gt;TRUE&lt;/Field&gt;<br />
&lt;Field Name=&#8221;Filterable&#8221;&gt;TRUE&lt;/Field&gt;<br />
&lt;Field Name=&#8221;FieldTypeClass&#8221;&gt;[5-PART STRONG NAME]&lt;/Field&gt;<br />
&lt;/FieldType&gt;<br />
&lt;/FieldTypes&gt;</p>
<p>You need to modify the FieldTypeClass element to insert the 5-part strong name of your field type class which we will create in a moment.</p>
<p>Each of the Field elements has a Name that is used to define the field type we are creating. The <strong>TypeName</strong> is the internal name used when we create columns from this field type. In the site column we created above this would match the Type attribute, which in our example was Text.</p>
<p>The ParentType is also vital, as it defines one of several root types from which our custom field type will inherit. You must always inherit your custom field type from another field type.</p>
<p>The TypeDisplayName and the TypeShortDescription are only for your eyes’ enjoyment, you can enter whatever values you like here. the UserCreatable states if users should be able to create new columns from this type, while the Sortable and Filterable states if the columns created from this field type should be sortable and filterable, respectively.</p>
<p>The AllowBaseTypeRendering specifies whether the field type should fall back to its parent rendering in case of problems rendering the field type.</p>
<p>Now for that FieldTypeClass.</p>
<p>WSPBuilder will happily sign your assembly for you to create a strong-named assembly. However, this only produces the four-part strong name. We need to prefix this four-part name with the name of our class. Which class you ask? Ah, we get to that when we create the…</p>
<h3>Field Type Class</h3>
<p>First, make sure you have added a reference to the Microsoft.SharePoint.dll to your project.</p>
<p>In the solution explorer, add a new class file to the root of your project. Name it something like SPMFieldType.cs. If you like, put it in a folder, but in any case, open the .cs file and add the following code:</p>
<p>using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using Microsoft.SharePoint;</p>
<p>namespace SPMType<br />
{<br />
public class SPMFieldType : SPFieldText<br />
{<br />
public SPMFieldType(SPFieldCollection fields, string fieldName)<br />
: base(fields, fieldName)<br />
{<br />
}</p>
<p>public SPMFieldType(SPFieldCollection fields, string typeName, string displayName)<br />
: base(fields, typeName, displayName)<br />
{<br />
}<br />
}<br />
}</p>
<p>One small thing first, before I forget. Let’s grab that five-part strong name we needed for the field type definition. First, build your solution, you may use the the WSPBuilder-&gt;Build WSP. Next, <a href="http://www.understandingsharepoint.com/justask/how-do-i-find-the-strong-name-of-an-assembly" target="_blank">find the four-part strong name of your assembly</a>. Finally, add the namespace.classname to the front of the strong name to create a five-part strong name. In my assembly this looks like this:</p>
<p>“SPMType.SPMFieldType, SPMType, Version=1.0.0.0, Culture=neutral, PublicKeyToken=817b2cbd5ec31d67”</p>
<p>Your PublicKeyToken will be different, as may your assembly, class, and namespace names.</p>
<p>Add this string to the FieldTypeClass element in your fldtypes_SPMType.xml field definition file.</p>
<p>Back to the class, we are inheriting from the SPFieldText class which makes sense since our parent type is Text. However, we are not bound by this, we can use any of the other SPFieldXXXX classes as the parent class for our own field type class.</p>
<p>Next we need to implement the constructors for our class, and SPFieldText determines the signatures for these constructors. For our class we don’t actually need to do anything but call the base constructor, but you can add functionality here to implement custom property handling or add other features as you see fit.</p>
<p>At this point we have actually created all we need to get our custom field type up and running. Of course, we’ve just created the most useless custom field type there is, as all we have done is implement the SPFieldText type, which is quite well done already by the built-in field type Text. However, we have a frame into which we can put a beautiful picture, so for now, just build (WSPBuilder-&gt;Build WSP) and deploy (WSPBuilder-&gt;Deploy) and sit back and wait. No need to activate anything, remember that custom field types are not deployed in features, so your field type will be available once the solution is deployed. Check this out in the Create new column of a list or when you go to create a new site column:</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/fieldtypedeployed1.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/fieldtypedeployed1-thumb.png" border="0" alt="FieldTypeDeployed1" width="662" height="444" /></a></p>
<p>If you add a column based on your new field type, it will behave exactly like a regular Text type, since we haven’t really added anything ‘Custom’ yet. Let’s add custom to the equation now.</p>
<h3>Custom Field Type Control</h3>
<p>Our first order of business is to create a control class to act as the rendering control for our new field type.</p>
<p>Start by adding a reference to System.Web since we will now deal with creating web controls.</p>
<p>Continue by adding yet another class file to the root of your project, this time called ‘SPMFieldControl.cs’ or something along those lines. To that class, add the following code:</p>
<p>using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using Microsoft.SharePoint;<br />
using Microsoft.SharePoint.WebControls;</p>
<p>namespace SPMType<br />
{<br />
public class SPMFieldControl : BaseTextField<br />
{<br />
}<br />
}</p>
<p>Note that we are inheriting from the BaseTextField class. Again, this is nothing extraordinary since we are creating a text class field type. However, for other field type classes you might want to inherit from another control.Here is a list of some of the Field controls from which we can inherit:</p>
<p>AllDayEventField<br />
AttachmentsField<br />
AttendeeField<br />
BaseChoiceField<br />
BaseTextField<br />
BooleanField<br />
CalculatedField<br />
ComputedField<br />
CrossProjectLinkField<br />
DateTimeField<br />
FieldValue<br />
FileField<br />
FormField<br />
LookupField<br />
ParentInformationField<br />
RatingScaleField<br />
RecurrenceField<br />
UrlField<br />
UserField</p>
<p>In addition, several of these, such as the BaseTextField have child types from which you also can inherit. The BaseTextField for example has BaseNumberField, NoteField, and TextField as child classes, and even more grand-children classes.</p>
<p>For our purposes, however, I really just want to show you the anatomy of a custom field type control, so we’ll base our control on the BaseTextField class.</p>
<p>First we must tell the control which template to use for rendering the control. We do this by overriding the DefaultTemplateName property as such:</p>
<p>protected override string DefaultTemplateName<br />
{<br />
get<br />
{<br />
return &#8220;TextField&#8221;;<br />
}<br />
}</p>
<p>The TextField is the default rendering template used for the single line of text field types we are mimicking. If you recall from Part 2 we looked at the DefaultTemplates.ascx file in the [12]\TEMPLATE\CONTROLTEMPLATES folder. This file also contains the TextField rendering template. This template is incredibly simple, but will do for the moment.</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/textfieldrenderingtemplate.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/textfieldrenderingtemplate-thumb.png" border="0" alt="TextFieldRenderingTemplate" width="659" height="91" /></a></p>
<p>At this point our control behaves like the default single line of text. Let’s add something to make sure we’re doing things right. Let’s override the RenderFieldForDisplay method which is use to, well, Render Field For Display. Bet you didn’t see that coming…</p>
<p>Add the following override to your SPMFieldControl class:</p>
<p>protected override void RenderFieldForDisplay(System.Web.UI.HtmlTextWriter output)<br />
{<br />
output.Write(&#8220;Custom displaymode: &#8220;);<br />
base.RenderFieldForDisplay(output);<br />
}</p>
<p>Again we’re simply relying on the underlying BaseTextField to do most of the manual labor, however adding the “Custom displaymode: “ enables us to see that we are in fact modifying the rendering of the field.</p>
<p>I’ll show you some more advanced samples in a moment, but for now, let’s connect our new field type control to the field type we created earlier. To do this, go back to your SPMFieldType.cs file, and add the following override to your class:</p>
<p>public override Microsoft.SharePoint.WebControls.BaseFieldControl FieldRenderingControl<br />
{<br />
get<br />
{<br />
SPMFieldControl c = new SPMFieldControl();<br />
c.FieldName = this.InternalName;<br />
return c;<br />
}<br />
}</p>
<p>You might want to add a ‘using Microsoft.SharePoint.WebControls;’ statement by the way, but that’s just for prettier code.</p>
<p>This code instantiates an object of our new control class and assigns the FieldName of that object to the field type internal name.</p>
<p>Finally, build your WSP as described above and redeploy. You may need to do an IISRESET to get your changes updated.</p>
<p>Try creating a new column based on your field type on a list and then add a new item. You will notice that the new column behaves exactly like a text field</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/customfieldtypenewitem.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/customfieldtypenewitem-thumb.png" border="0" alt="CustomFieldTypeNewItem" width="706" height="279" /></a></p>
<p>I bet by now you’re going: “Aw, come one, we haven’t seen any custom rendering at all, only mimicking of the default single line of text”. Patience, young Skywalker.</p>
<p>Add your new item and the display that item. Let’s see if your 1 second of patience has paid off:</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/customfieldtypedisplayitem.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/customfieldtypedisplayitem-thumb.png" border="0" alt="CustomFieldTypeDisplayItem" width="699" height="251" /></a></p>
<p>Wohoo! Congratulations, you’ve just made… Well, absolutely nothing if you ask your boss, but hey, you made it yourself, right? That’s got to be worth something. Let’s see if we can impress your boss as well.</p>
<p>Oh, yeah, the date. I got a bit delayed writing this article.</p>
<h2>One Step Further</h2>
<p>Ok, so we have wired up our field type and we have connected that field type to a field control. We might as well utilize that to our advantage.</p>
<p>We want to create our own rendering template and not rely on the DefaultTemplates.ascx template. After all, we might want to add a nice Ajax control, or perhaps even a Silverlight control? No, I wont do that for you, that’s a completely different show, but I’ll show you how to create your own rendering template.</p>
<p>First, in your solution explorer, add a folder named CONTROLTEMPLATES to the TEMPLATE folder under the 12 folder.</p>
<p>Inside the CONTROLTEMPLATES folder, still in solution explorer, add a new Text file, and name it MyCoolTextBox.ascx. Using a text file but naming it .ascx makes Visual Studio recognize the file as a web user control even if this is not a web project.</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/solutionexplorercustomcontrol.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/solutionexplorercustomcontrol-thumb.png" border="0" alt="SolutionExplorerCustomControl" width="289" height="326" /></a></p>
<p>Next, open the MyCoolTextBox.ascx and add the following outline:</p>
<p>&lt;%@ Control %&gt;<br />
&lt;%@ Assembly Name=&#8221;Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&#8221; %&gt;<br />
&lt;%@ Register TagPrefix=&#8221;SharePoint&#8221; Assembly=&#8221;Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&#8221;<br />
Namespace=&#8221;Microsoft.SharePoint.WebControls&#8221; %&gt;<br />
&lt;SharePoint:RenderingTemplate ID=&#8221;MyCoolTextBox&#8221; runat=&#8221;server&#8221;&gt;<br />
&lt;Template&gt;<br />
&lt;/Template&gt;<br />
&lt;/SharePoint:RenderingTemplate&gt;</p>
<p>Now, inside the Template tag, let your designers go bananas. Yes, I mean bananas, designers always love that. I’ll add one provision for now: Make sure you have an ASP:TextBox control with an Id of “TextField”. I’ll explain why in a moment. Besides that, do whatever you like.</p>
<p>Finally we need to tell our control to use the new rendering template. Go back into the SPMFieldControl and update the DefaultTemplateName override as such:</p>
<p>protected override string DefaultTemplateName<br />
{<br />
get<br />
{<br />
return &#8220;MyCoolTextBox&#8221;;<br />
}<br />
}</p>
<p>By the way, if you ever get the error ‘Corrupted control template. Please check RenderingTemplate of &#8220;TextField&#8221; in the control template ascx file.’ while working with the BaseTextField class, don’t bother checking your TextField template, as the name ‘TextField’ is hardcoded in the Microsoft.SharePoint.dll. I just spent two hours chasing after the wrong rendering template. Now you don’t have to.</p>
<p>Back to our fancy new rendering template. Before you go and deploy your new WSP, uninstall the old one using WSPBuilder-&gt;Uninstall. The reason is that by default WSPBuilder will upgrade your solution. Upgrading a solution does not add new files, and since we just added our new ascx control we need to make a clean install. After the uninstall completes, go ahead and deploy as normal.</p>
<p>Depending on what you decided to put inside the Template tag of your control you will see your changes when you refresh your Edit or New form. I’ve added</p>
<p>&lt;asp:TextBox ID=&#8221;TextField&#8221; runat=&#8221;server&#8221; BackColor=&#8221;Cyan&#8221; BorderStyle=&#8221;None&#8221;&gt;&lt;/asp:TextBox&gt;</p>
<p>to my control and get this:</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/customfieldcustomtemplate.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/customfieldcustomtemplate-thumb.png" border="0" alt="CustomFieldCustomTemplate" width="664" height="256" /></a></p>
<p>For some reason I never got a job offer as a designer. Go figure, I think this looks beautiful.</p>
<p>Before I wrap up with some final thoughts and some further resources for you, I’d like to explain a bit of the magic that goes on here. You see, when we inherited our control class from the BaseTextField class we got a ton of free functionality. The BaseTextField searches for a TextBox control with an Id of “TextField” inside whatever renderingtemplate we send it. If the BaseTextField finds such a TextBox it gladly hooks up all the required functionality for us, including populating the TextBox with the right values when editing. This happens in the CreateChildControls() method of the BaseTextField class.</p>
<p>By not overriding the CreateChildControls() in our own class we basically get that functionality for free. See why having a TextBox with an Id of “TextField” makes sense now? Of course, you can override the CreateChildControls() if you want absolute and complete control over the building of your control, but I think it makes sense to let Microsoft work a bit for all the money we send them, and letting them handle as much of the nitty-gritty details as possible is at least sensible to me.</p>
<h1>Wrap Up and More Resources</h1>
<p>Ok, before you all go yelling at me for not including details on writing your own field type value, remember that this is a user experience series, and I hardly see how managing data internally is part of the user experience. Also, this article is quite long enough as it is, so instead I’ll point you to another article here no SharePoint Magazine: <a href="http://sharepointmagazine.net/technical/development/developing-a-sharepoint-custom-field-type-for-displaying-crm-40-data" target="_blank">Developing a SharePoint Custom Field Type for Displaying CRM 4.0 Data</a>. This article also shows you how you can use a code-behind file as part of your control.</p>
<p>I do hope I have conveyed a bit of knowledge, however, both on columns and on custom field types, and that you are left with a bit more confidence when facing one of the most complex tasks a SharePoint developer will face.</p>
<p>Tomorrow I’ll take you on a fast-track to feature generation and show you how you can speed up your SharePoint feature development by using the right tools and utilizing the web interface to create a lot of the nitty-gritty CAML required for features.</p>
<p>Don’t forget to leave feedback. If you have questions or comments I love to hear about it!</p>
<p>.b</p>
]]></content:encoded>
			<wfw:commentRss>http://sharepointmagazine.net/technical/development/customizing-the-user-experience-of-sharepoint-custom-fields-deep-dive-part-5-of-6/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Customizing the User Experience of SharePoint: Content Type User Interface (Part 4 of 6)</title>
		<link>http://sharepointmagazine.net/technical/development/customizing-the-user-experience-of-sharepoint-content-type-user-interface-part-4-of-6</link>
		<comments>http://sharepointmagazine.net/technical/development/customizing-the-user-experience-of-sharepoint-content-type-user-interface-part-4-of-6#comments</comments>
		<pubDate>Tue, 24 Feb 2009 07:00:12 +0000</pubDate>
		<dc:creator>furuknap</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[CAML]]></category>
		<category><![CDATA[content]]></category>
		<category><![CDATA[experiance]]></category>
		<category><![CDATA[metadata]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[type]]></category>
		<category><![CDATA[User]]></category>
		<category><![CDATA[usx]]></category>

		<guid isPermaLink="false">http://sharepointmagazine.net/?p=2682</guid>
		<description><![CDATA[SharePoint Magazine User Experience week continues with an article dedicated to content types and their user interfaces.]]></description>
			<content:encoded><![CDATA[<p>After a considerably shorter break, it is time for the fourth part of the “Customizing the User Experience of SharePoint” series. This article is also the second day of SharePoint User Experience week here on <a href="http://sharepointmagazine.net/" target="_blank">SharePoint Magazine</a>. One full week, focusing only on understanding SharePoint architecture from a user experience point of view. Christmas all week long, if you ask me.</p>
<p>The Customizing the User Experience of SharePoint series aims to explain how the user experience works, from how the interface is built down to details on how columns in lists get created.</p>
<p>The series is also an exclusive preview of the topics from my upcoming book, “<a title="SharePoint Developer book" href="http://www.understandingsharepoint.com/userexperience" target="_blank">Building the SharePoint User Experience</a>”, which deals with SharePoint user experience for 350 pages. Actually, as with this series, the book explains the SharePoint architecture from a user experience perspective.</p>
<p>Here is an article outline for the six parts:</p>
<p><strong>Part 1: Overview of the default SharePoint interface from a technical point of view</strong></p>
<p>In the first article we will look at how the default SharePoint interface is built. We will look at a site, going from top-down, explore some of the the default lists, the fields used to create the basic field types, which content types are available, and how list forms are rendered.</p>
<p><strong>Part 2: Modifying the default experience </strong></p>
<p>This article will show you which options are available for you to modify and improve the default setup. Learn how to override the default rendering of fields or forms without voiding your supported state.</p>
<p><strong>Part 3: Lists and custom list forms </strong></p>
<p>The third article will cover the basics of customizing lists using different views, custom list forms, and fields.</p>
<p><strong>Part 4: Content types user interface</strong></p>
<p>The next article will explore how you can utilize content types to display different input forms and display forms.</p>
<p><strong>Part 5: Custom fields deep dive </strong></p>
<p>Ever wanted to create a new field type? SharePoint enables you to do this and it is a very powerful tool for customizing the user experience.</p>
<p><strong>Part 6: Fast track to feature generation </strong></p>
<p>Writing custom lists with content types by hand can take a massive amount of time. In the final installment I will share with you some tools and techniques that makes list, field, and content type generation very fast.</p>
<p>This time, however, we’ll focus on a really cool feature of SharePoint…</p>
<h1>Content Types</h1>
<p>If you haven’t worked with content types before you haven’t worked with SharePoint since WSS2 and the SPS2003 era. You may not realize this, but Content Types are the method by which you store data in SharePoint, whether you like it or not.</p>
<p>Content Types are schemas for information, defining what your items or documents should contain, how they should behave, and, most importantly for us in this article, how they should appear.</p>
<p>Before we go into user experience customization of content types, you should also know a few more things about content types:</p>
<ul>
<li>Everything stored in SharePoint uses a content type, even if you do not explicitly enable content types on a list or library.</li>
<li>Folders themselves are just special items created from a folder content type.</li>
<li>Content types can also store metadata about their derived items.</li>
<li>Content Types support inheritance, meaning you can have a content type hierarchy and store common information in a parent type.</li>
<li>Scoping of content types means you can target content types to specific site collections or sites and have child sites have access to the same content types.</li>
</ul>
<p>The second issue of <a title="Learn SharePoint with Understanding SharePoint Journal" href="http://www.understandingsharepoint.com/journal" target="_blank">Understanding SharePoint Journal</a> deals exclusively with content types, showing off some of the magnificent things you can accomplish if you understand this technology.</p>
<p>However, for this article we will focus on learning how we can make content types appear the way we want.</p>
<h1>The Anatomy of a List Form</h1>
<p>As we have explored earlier in this series, list forms are customizable forms used to display, edit, or create new items in a list. These forms are made up of form pages, which we can customize to make a nicer interface for the users. For most of the default list templates in SharePoint, a single ASP.NET page, the [12]\TEMPLATE\Pages\form.aspx page, is used to render all list forms.</p>
<p>However, in a single list we can have multiple content types. For example we can have a document library store both Financial and Legal documents, each of which may require a separate set of metadata. There must be a way for SharePoint to know which set of metadata to display or which form fields we need to fill in to update or create an item.</p>
<p>The answer is that a list form is made up of two parts. One is the list form page, which determines the outline of the form. The other part is the content type form, which defines the specifics of the individual item or document.</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/contenttypedisplayform.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/contenttypedisplayform-thumb.png" border="0" alt="ContentTypeDisplayForm" width="891" height="435" /></a></p>
<p>In the above image, the area inside the red square is made from the content type’s display form, while the rest of the page is made up of the list’s display form. Of course, the list form page can also be made up of master pages and regular content, as is the case for all the default list forms.</p>
<p>There is also another option, which is to have the whole page tied to a content type. In such a case, the list form page would not be used at all. We will look at this in a moment.</p>
<p>Now, to understand how this anatomy is constructed we need to dig a bit into how content types are created and learn a bit about how content type inheritance works.</p>
<p>As you would also know you can override these forms by creating a new .ascx user contol in the CONTROLTEMPLATES folder and put a SharePoint:RenderingTemplate control inside with the same ID as the template you want to replace.</p>
<h2>Content Type inheritance</h2>
<p>Content types support inheritance, with a bit of a peculiar method of defining inheritance. In simple terms this means that you can create a hierarchy of content types, just like a class hierarchy, and have child content types inherit properties from parents and grandparents.</p>
<p>What differs significantly from other hierarchical systems is a rather awkward method for describing inheritance in SharePoint content types. Every content type in SharePoint has a unique identifier, the content type Id. When you create a content type you define a content type id that is of the format 0xNNNNNNN where NNNNNNN is a number. That number not only identifies this content type but also from which parent content type we should inherit. That’s right, no kidding, inheritance is hidden inside the identifier string.</p>
<p>All you need to do to inherit from a content type is to include the parent content type id in your content type id and then add a few numbers.</p>
<h3>Crafting Content Type IDs</h3>
<p>Oh, yeah, how you add those numbers matter a great deal. Let’s look at the default content types to see how this is done. Open the [12]\TEMPLATE\FEATURES\ctypes folder and then the ctypeswss.xml file. This is where all the default content types are defined.</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/ctypeswssxml.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/ctypeswssxml-thumb.png" border="0" alt="ctypeswss.xml" width="911" height="485" /></a></p>
<p>First, notice that the first ContentType element, named System, has an ID value of 0x. All content types must inherit at least from this system content type. The type itself defines only a single column or field reference, the ContentType field.</p>
<p>The next content type is the Item content type, and you can see from the ID value the first method of creating inheritance. Adding two numbers, for example 01, 02, or 99, is one way of inheriting from a parent type. If you wanted to inherit directly from System you could have your content type have and id of 0&#215;02, 0&#215;03, etc.</p>
<p>The other method for crafting content type ids is to add 00 and then a Guid string without the hypens. For example you may have an id that inherits directly from Item as such:</p>
<p><span style="#ff0000;">0x</span><span style="#008000;">01</span><span style="#0000ff;">00</span><span style="#ff8000;">1A48C1A2B071432EACA85A0A35FF5185</span></p>
<p>Break that ID down and you will see <span style="#ff0000;">System (0x)</span>, <span style="#008000;">Item (01)</span>, <span style="#0000ff;">two zeros (00)</span>, and a GUID (<span style="#ff8000;">1A48C1A2B071432EACA85A0A35FF5185</span>).</p>
<p>The properties of a content type are inherited from its parent. In the Item content type this means we inherit the ContentType column from System, and, as you can see, adds a new field, the Title field. In addition the Item content type defines an XmlDocument which contain a FormTemplates element. Inside the FormTemplates are names of forms that will be used for display, edit, and new forms for items based on the Item content type. And, knowing that these properties are inherited we can deduce that all content types inheriting from Item will use the ListForm template.</p>
<h3>Overriding property inheritance</h3>
<p>Now, using the same form for all content types may be a bit too limiting for you. You’ll be thrilled, I’m sure, to learn that you can override any property for child content types simply by adding an overriding value. The Document content type is an examle of this. To examine property overriding, scroll further down in the ctypeswss.xml file to the Document content type, which, in my file, is around line 32.</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/documentcontenttype.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/documentcontenttype-thumb.png" border="0" alt="DocumentContentType" width="887" height="574" /></a></p>
<p>Notice that the Document content type adds the Title field again, even if it is added in the parent Item content type. If you examine the FieldRef elements of Item and Document, however, you will notice that the attributes differs. This way, in Document based items, the Title is not required, and will not appear in NewForm.</p>
<p><strong>Item Title FieldRef:<br />
</strong>&lt;FieldRef ID=&#8221;{fa564e0f-0c70-4ab9-b863-0177e6ddd247}&#8221; Name=&#8221;Title&#8221; Required=&#8221;TRUE&#8221; ShowInNewForm=&#8221;TRUE&#8221; ShowInEditForm=&#8221;TRUE&#8221;/&gt;</p>
<p><strong>Document Title FieldRef:<br />
</strong>&lt;FieldRef ID=&#8221;{fa564e0f-0c70-4ab9-b863-0177e6ddd247}&#8221; Name=&#8221;Title&#8221; Required=&#8221;FALSE&#8221; ShowInNewForm=&#8221;FALSE&#8221; ShowInEditForm=&#8221;TRUE&#8221;/&gt;</p>
<p>Another thing to notice is that Document also overrides the FormTemplates to replace these with DocumentLibraryForm.</p>
<h2>Customizing Content Type Forms</h2>
<p>Now, as I am certain you have been reading the first and second parts of this series you know a few things about where these forms are actually stored. To remind you, the default forms used by SharePoint, such as ListForm and DocumentLibraryForm, as stored in the [12]\TEMPLATE\CONTROLTEMPLATES\DefaultTemplates.ascx file.</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/defaulttemplatesascx.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/defaulttemplatesascx-thumb.png" border="0" alt="defaulttemplates.ascx" width="880" height="442" /></a></p>
<p>However, that may not be a possibility for you. First of all, overriding is am all-or-nothing deal; you override for all templates throughout the farm. Second you can only override once, meaning if you have overridden the ListForm template once you cannot add a second ListForm template and expect some magic to determine which one will be used. In fact, from what I’ve been able to deduce, file naming determines which rendering template will be used if you add two templates with the same Id. In the next image I have added two rendering template files, one called aform.aspx and one called bform.aspx, both of which simply displays a text, either A or B, and as you can see, the B Form is used:</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/bform.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/bform-thumb.png" border="0" alt="Bform" width="662" height="223" /></a></p>
<p>However, I do not actually know this since this part of the code in Microsoft.SharePoint.dll is obfuscated.</p>
<p>Still, nothing prevents us from creating our own forms for use with our own content types.</p>
<ol>
<li>Start out by creating a new .ascx file in the [12]\TEMPLATE\CONTROLTEMPLATES folder.</li>
<li>Name it whatever you like. Next, copy the directives from the defaulttemplates.ascx file:</li>
</ol>
<p>&lt;%@ Control Language=&#8221;C#&#8221; AutoEventWireup=&#8221;false&#8221; %&gt;<br />
&lt;%@ Assembly Name=&#8221;Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&#8221; %&gt;<br />
&lt;%@ Register TagPrefix=&#8221;SharePoint&#8221; Assembly=&#8221;Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&#8221;<br />
Namespace=&#8221;Microsoft.SharePoint.WebControls&#8221; %&gt;<br />
&lt;%@ Register TagPrefix=&#8221;SPHttpUtility&#8221; Assembly=&#8221;Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&#8221;<br />
Namespace=&#8221;Microsoft.SharePoint.Utilities&#8221; %&gt;<br />
&lt;%@ Register TagPrefix=&#8221;wssuc&#8221; TagName=&#8221;ToolBar&#8221; Src=&#8221;~/_controltemplates/ToolBar.ascx&#8221; %&gt;<br />
&lt;%@ Register TagPrefix=&#8221;wssuc&#8221; TagName=&#8221;ToolBarButton&#8221; Src=&#8221;~/_controltemplates/ToolBarButton.ascx&#8221; %&gt;<br />
&lt;%@ Register TagPrefix=&#8221;WebPartPages&#8221; Namespace=&#8221;Microsoft.SharePoint.WebPartPages&#8221;<br />
Assembly=&#8221;Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&#8221; %&gt;</p>
<ol>
<li>Then, just to make things simple, copy the ListForm rendering template from the same file, but change the ID from ListForm to MyListForm. Make some random change to recognize your custom form, for example by adding My list form after the Span HTML tag:</li>
</ol>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/customform.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/customform-thumb.png" border="0" alt="CustomForm" width="744" height="336" /></a></p>
<p>Congratulations, you’ve just created a new content type form.</p>
<p>Now you need to attach it to a content type. I’ll walk you through a simple example to demonstrate.</p>
<ol>
<li>Create a new site content type from the site settings page. Name it whatever you like, and inherit from the Item content type. Add some site columns if you like.</li>
<li>In a test list, go to list settings and then Advanced Settings. Enable ‘Allow management of content types’ and hit Ok.</li>
<li>Back in the site settings, add a content type from existing site content types, and add your new content type.</li>
<li>Go back the list and add a new item based on your content type.</li>
</ol>
<p>Now we have an actual content type to which we can attach our new form.</p>
<ol>
<li>Get <a href="http://www.codeplex.com/spm" target="_blank">SharePoint Manager 2007</a>. Yeah, it’s free, and it’s the best tool you’ll ever own, including whatever free chocolate machine you may already have.</li>
<li>Browse to the site where you created your content type and open the Content Types node. Locate your new content type.</li>
<li>In the properties window, locate the DisplayFormTemplateName. Notice that it is set to ListForm. Change this to MyListForm and then hit Save. I’ll repeat the last instruction. Hit Save.</li>
</ol>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/spm2007.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/spm2007-thumb.png" border="0" alt="SPM2007" width="673" height="542" /></a></p>
<p>In case you missed it, you need to hit Save before your changes are added to SharePoint.</p>
<p>Next, re-open your item in the list.</p>
<p>And at this point you are likely going to be very angry with me because your form will not work at all and be completely blank. However, there is a very reasonable explanation for this, and I just wanted you to see this error, since I make it myself all the time.</p>
<p>You see, control templates are only read after an IISRESET. So, to make your wonderful new form appear, simply IISRESET (c:\&gt;iisreset) and your form should appear just fine, including your customizations:</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/mylistform.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/mylistform-thumb.png" border="0" alt="MyListForm" width="494" height="269" /></a></p>
<p>Cool, eh?</p>
<h1>Stop being so cool!</h1>
<p>Ok, I think we had enough for this article. We’ve covered the basics of content types and examined how inheritance works. You’ve seen how content types are defined and also how you can create your own content type forms.</p>
<p>However, this is only the beginning of content types. If you think what you have seen here is cool, issue 2 of Understanding SharePoint Journal will totally blow your mind. We’ll examine behavior with workflow and event receivers, look at how folders are content types and how you can use this in SharePoint, and also how you can extend your content types using XmlDocuments.</p>
<p>As of this writing, issue 2 is not out yet, but you can always sign up for the <a href="http://www.understandingsharepoint.com/journal/uspj-mailing-list" target="_blank">Understanding SharePoint Journal mailing list</a> to be notified when the issue ships. Or, if you are reading this article later than the issue date you can visit the <a title="Learn SharePoint with Understanding SharePoint Journal" href="http://www.understandingsharepoint.com/journal" target="_blank">USP Journal webpage</a> and grab a copy.</p>
<p>The next part of this series will deal with columns and field types, teaching you the basics you need to understand how these elements influence the user experience.</p>
<p>Until next time, however I hope you have a great time with what you’ve learned here.</p>
<p>.b</p>
]]></content:encoded>
			<wfw:commentRss>http://sharepointmagazine.net/technical/development/customizing-the-user-experience-of-sharepoint-content-type-user-interface-part-4-of-6/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Customizing the User Experience of SharePoint: Lists, Custom list forms, and CAML Views (Part 3 of 6)</title>
		<link>http://sharepointmagazine.net/technical/development/customizing-the-user-experience-of-sharepoint-lists-custom-list-forms-and-caml-views-part-3-of-6</link>
		<comments>http://sharepointmagazine.net/technical/development/customizing-the-user-experience-of-sharepoint-lists-custom-list-forms-and-caml-views-part-3-of-6#comments</comments>
		<pubDate>Mon, 23 Feb 2009 06:55:36 +0000</pubDate>
		<dc:creator>furuknap</dc:creator>
				<category><![CDATA[Customisation]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[CAML]]></category>
		<category><![CDATA[experiance]]></category>
		<category><![CDATA[lists]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[User]]></category>
		<category><![CDATA[usx]]></category>

		<guid isPermaLink="false">http://sharepointmagazine.net/?p=2665</guid>
		<description><![CDATA[SharePoint Magazine shows you users experience customization through lists, list forms, and custom CAML view creation.]]></description>
			<content:encoded><![CDATA[<p>Finally, after a very, very, very, vey, very, very long break, here is part 3 of the “Customizing the User Experience of SharePoint” series. This article also launches the SharePoint User Experience week here on <a href="http://sharepointmagazine.net/" target="_blank">SharePoint Magazine</a>. One full week, focusing only on understanding SharePoint architecture from a user experience point of view. It doesn’t get any better than this.</p>
<p>The Customizing the User Experience of SharePoint series aims to explain how the user experience works, from how the interface is built down to details on how columns of lists get created.</p>
<p>The series is also an exclusive preview of the topics from my upcoming book, “<a title="SharePoint Developer book" href="http://www.understandingsharepoint.com/userexperience" target="_blank">Building the SharePoint User Experience</a>”, which deals with SharePoint user experience for 350 pages. Actually, as with this series, the book explains the SharePoint architecture from a user experience perspective.</p>
<p>Here is an article outline for the six parts:</p>
<p><strong>Part 1: Overview of the default SharePoint interface from a technical point of view</strong></p>
<p>In the first article we will look at how the default SharePoint interface is built. We will look at a site, going from top-down, explore some of the the default lists, the fields used to create the basic field types, which content types are available, and how list forms are rendered.</p>
<p><strong>Part 2: Modifying the default experience </strong></p>
<p>This article will show you which options are available for you to modify and improve the default setup. Learn how to override the default rendering of fields or forms without voiding your supported state.</p>
<p><strong>Part 3: Lists and custom list forms </strong></p>
<p>The third article will cover the basics of customizing lists using different views, custom list forms, and fields.</p>
<p><strong>Part 4: Content types user interface</strong></p>
<p>The next article will explore how you can utilize content types to display different input forms and display forms.</p>
<p><strong>Part 5: Custom fields deep dive </strong></p>
<p>Ever wanted to create a new field type? SharePoint enables you to do this and it is a very powerful tool for customizing the user experience.</p>
<p><strong>Part 6: Fast track to feature generation </strong></p>
<p>Writing custom lists with content types by hand can take a massive amount of time. In the final installment I will share with you some tools and techniques that makes list, field, and content type generation very fast.</p>
<h1>A Short Recap</h1>
<p>It’s been a while since the last article, so I thought that at least I should post a short recap of where we have been, in case you cannot be bothered to read <a href="http://sharepointmagazine.net/technical/development/customizing-the-user-experience-of-sharepoint-overview-of-the-default-sharepoint-interface-from-a-technical-point-of-view-part-1-of-6" target="_blank">Part 1</a> and <a href="http://sharepointmagazine.net/technical/development/customizing-user-experience-sharepoint-modifying-default-experience-part-2-6" target="_blank">Part 2</a>.</p>
<p>In the first part we examined how a site was built from various different XML files, including webtemp.xml, onet.xml, and the global site definition. We then briefly touched on list templates, content types, list forms, columns and fields, and views, mostly to know what was ahead.</p>
<p>In the second part we looked at some methods we can use to customize the default user experience and learned what will break out supportability. We examined CustomActions and saw how we can override ControlTemplates to modify how visual elements of a SharePoint site are rendered. I also mentioned two other articles here on <a href="http://sharepointmagazine.net/" target="_blank">SharePoint Magazine</a> that deal with custom master pages and feature stapling.</p>
<p>On that note, however, I would like to point out that these methods are not your only options for customizing the default user experience. One thing that really deserves more attention is DelegateControls, a method by which you can add content to a page using a feature. This is how Search Server and MOSS changes the search box and adds ‘My Site’ and ‘My Links’ as well as the publishing console.</p>
<p>Back to lists.</p>
<h1>Lists and List Templates</h1>
<p>When I talk to developers, and especially developers who are new to SharePoint, talking about lists is a bit confusing. First, lists seems to be a somewhat ambiguous term, sometimes referring to lists and sometimes referring to list templates. Before we dive into details I want to just make sure you are up to snuff on the difference.</p>
<p>A list template is a template for how new list instances will be created. A list template holds most of the content which will make up the lists, including the default columns, permissions, views, content type bindings, and forms. When you go to the Create page of a SharePoint site, the columns you see, with the exception of the Web Pages column, are filled with the default List Templates that get deployed as part of the Team Collaboration Lists feature.</p>
<p>That last statement is important; the list templates get deployed using features. While you have the option of defining list templates as part of a site definition, you don’t want to do that. If you watched the SharePoint blogosphere a few months back there was a gentle reminder from absolutely every sane person alive to keep as little as possible inside the site definition. I think <a rel="nofollow" href="http://www.andrewconnell.com/blog/archive/2008/02/15/You-dont-need-to-create-site-definitions.aspx" target="_blank">Andrew Connell</a> has a very nice explanation of why you want to keep stuff in features and leave your site definitions as small as possible.</p>
<p>List instances, on the other hand, are what you create when you click one of the templates on the Create page. These are, as the name implies, instances of the list templates. You store data in a list instance, and this is also where you would add columns, attach workflows to items, etc.</p>
<p>You can deploy list instances using features, and this makes a lot of sense when you are creating a SharePoint solution in which you need to store data for your solution. However, your options for customizing a single list instance through features are a bit limited. For example, you cannot define additional columns to a list using an elements.xml file, nor can you add or modify views in a feature. At least not unless you add a feature receiver and modify the list instance using code.</p>
<p>With these distinctions out of the way, let’s get into the details of how these elements are built and how we can manipulate how the users experience our lists.</p>
<h1>List User Experience Options</h1>
<p>Users interact with lists using two visual interfaces, the list forms and the views. These are in fact closely tied together as we will see in a moment.</p>
<h2>List forms</h2>
<p>A list form is a regular ASP.net page the serves as the visual interface of a list. List forms are defined in the list template, but the forms are instantiated in a list instance. This means that we can override the list forms for each list by customizing the list forms that are instantiated with the list.</p>
<p>The list form definitions tell SharePoint from where each list form should be instantiated. If you examine the Custom List list template, located in the [12]\TEMPLATE\FEATURES\CustomList\CustList\schema.xml file, you can see the Forms section near the bottom:</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/customlistschemaxml.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/customlistschemaxml-thumb.png" border="0" alt="CustomList.schema.xml" width="914" height="149" /></a></p>
<p>Each of the Form elements you see here represents one state or display mode of list items, as specified in the <strong>Type</strong> attribute. The <strong>Url</strong> attribute defines the list-relative Url where the list form will be instantiated. I’ll skip the SetupPath for a moment and tell you that <strong>WebPartZoneID</strong> defines which webpart in the ASP.NET page should hold the contents of the list form.</p>
<p>The SetupPath tells SharePoint what should be the source of the list form. As we saw in the first part of the series, SetupPath is relative to the [12]\TEMPLATE folder, so if you open [12]\TEMPLATE\pages you should see a file called form.aspx. If you don’t, well, you’re either in trouble or you know extremely well what you are doing. If you open that file you will notice that it is indeed a very normal ASP.NET file. No magic here.</p>
<p>One really important thing to note, however, is that until you decide to customize a list form the form will still point to the source. Changes to the pages\form.aspx will reflect on every list form that still points to the original source.</p>
<p>If you decide to create your own list templates, however, you may point your list forms elsewhere. In that case you would likely replace SetupPath with Path, since Path is feature-relative, while SetupPath is [12]\TEMPLATE relative.</p>
<p>You may want to change a list form for a specific list instance. You now know that each of the list forms gets virtually stored in the path specified in Url attribute. These form pages can be customized using the customization framework of SharePoint. If you haven’t worked with this before, here’s the executive summary:</p>
<p>When you customize a page, meaning you change the ASP.NET code, SharePoint will unlink the page from the source, and copy the page into the SharePoint database. Then, al changes you make to the customized page gets written to the database instead of the source file. SharePoint will keep track of whether your page is customized and retrieve the page from the correct source.</p>
<p>To perform such a customization the easiest method is to grab a copy of SharePoint Designer, or SPD for short. SPD is tightly integrated with SharePoint and fully supports working with customized files. When you start SPD and connect to your site you will be able to browse into the list containing the form you wish to customize. Simply double-click any of the forms to open it and the hit Save to customize the form and remove its link to the source pages\form.aspx. SPD will warn you about customizing forms, but after you click Yes to acknowledge the warning, you are free to modify the list form as you see fit.</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/spdcustomizeform.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/spdcustomizeform-thumb.png" border="0" alt="SPDCustomizeForm" width="642" height="652" /></a></p>
<p>You can also define a completely new ASP.NET page to take over any of the existing list forms. This is done, in SPD, by going to the list properties and selecting Supporting Files where you will be allowed to browse for a different page. If you want to do this you must make sure that the new page contains the correct list form to use for the corresponding display mode, either NewForm, DisplayForm, or EditForm. To insert such a form on a page, place the cursor where you want the new form and go to Insert-&gt;SharePoint Controls-&gt;List forms.</p>
<p>You may not immediately realize that this is a cool thing, but consider this: You can link your list forms to a page stored in a library. That’s right, suddenly your list forms are editable from the web interface, allowing you to customize the user experience of modifying data in SharePoint, all through the web interface.</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/customeditform.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/customeditform-thumb.png" border="0" alt="CustomEditForm" width="646" height="423" /></a></p>
<p>No more using SPD every time you want to modify the list forms. Cool, eh?</p>
<p>Of course, such an approach carries significant security issues, so you would need to limit permissions to the forms page library or pages. But you should know you have the option.</p>
<p>Speaking of content, which we weren’t, but I need a segue, where do the actual form content enter the scene? All the form elements derives from the same form.aspx source page, so there must be something that tells SharePoint which columns to put into which forms. The answer will be discussed more in part 4, however for now you should know that the actual form, meaning the columns, are not rendered from the list at all, but rather from the content types.</p>
<p>Content types carry their own set of forms that are used to render the display, editing, and new forms for items based of the content type. The cool thing about this is that you can tie the rendering of items to the type of item, not on where it is stored. Override the default forms used and you can create visually stunning displays. Here’s one example I have in the book “Building the SharePoint User Experience”:</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/empiretimessample.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/empiretimessample-thumb.png" border="0" alt="EmpireTimesSample" width="821" height="653" /></a></p>
<p>You’ll learn how to create content type specific forms in the next art of the series. Note that the title is made using a custom field type, which will be covered in part five.</p>
<h2>Views</h2>
<p>Your other option for customizing the user experience of list is views. You’ve probably worked with view through the web interface. Basically it is a view of data of a list, such as the AllItems.aspx view, which shows all items or documents in a list.</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/alldocumentsview.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/alldocumentsview-thumb.png" border="0" alt="AllDocumentsView" width="647" height="495" /></a></p>
<p>Strictly speaking, AllItems.aspx is a view page, not a view. The view is All Items, or, as in the previous screenshot, All Documents, but it is displayed on a view page.</p>
<p>These views are declaratively defined in the list template, in the Views section of the schema.xml file. This section defines any views that are available by default for new list instances based on the template. In addition you can create new views after the list has been created either by using the web interface, or, as developers, through code.</p>
<p>However, some more advanced aspects of view creation can not be handled through code or the web interface at all. I am, of course, talking about the dreaded CAML View schema.</p>
<h2>CAML view creation</h2>
<p>Now, before you go hiding in the closet, swearing not to exit before I promise not to talk more about views, let me calm your fear of custom view development by saying that we will not be doing anything really advanced here. A lot of developers have a natural fear of SharePoint custom view development. However, if you beak down views into manageable chunks, creating custom views is no harder than learning to ice skate. Yes, it is painful the first times you fall, but once you get the hang of it is great fun. And cold. And hard. Oh, well…</p>
<p>Open the Custom List schema.xml, located in the [12]\TEMPLATE\FEATURES\CustomList\CustList folder. Close all elements except the <em>Views</em> element. Next, close the View element with BaseViewId=”0”. This is the default view that is used when you add a list view to a web part using the web interface. By the way, if you create your own list template and you’re unable to add lists based on that template to a web part page you are most likely missing the BaseViewId=”0” view. The error message would be ‘Unable to add selected web part(s). [List name]: List View Web Part could not be added, list may be hidden.</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/nodefaultview.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/nodefaultview-thumb.png" border="0" alt="NoDefaultView" width="442" height="130" /></a></p>
<p>Next, inside the View with BaseViewId=”1”, close the first-level child elements. These would be GroupByHeader, GroupByFooter, ViewHeader, ViewBody, ViewFooter, PagedRowset, PagedClientCallbackRowset, PagedRecurrenceRowset, RowLimit, ViewEmpty, Toolbar, ViewFields, and Query. These elements are what constitutes a view. The good news is that quite often you wont need to deal with all of these, only 4-5 are really necessary. The bad news is that dealing with any of these requires you to write View CAML.</p>
<p>When you feel brave enough, open the ViewBody element, and I’ll walk you through the basics.</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2009/02/viewbody.png"><img style="0px" src="http://sharepointmagazine.net/wp-content/uploads/2009/02/viewbody-thumb.png" border="0" alt="ViewBody" width="788" height="717" /></a></p>
<p>ViewBody, by the way, is called once for each list item in our list. This is in contrast with other View elements, such as ViewHeader and ViewFooter, which are called only once.</p>
<p>The Views of a list are usually used to output the HTML we need to send back to the browser, so if you keep thinking that we are building a HTML document it can be a bit easier to wade through all this stuff. And, since the View schema is completely XML based, we need to adhere to XML rules. This means that whenever we want to include plain HTML we must encapsulate that HTML in a CDATA element. This is exactly what happens in the first line (1505) where we say that we want to output HTML and then contain the actual HTML inside a CDATA element.</p>
<p>Our HTML so far is ‘<span style="#ff0000;">&lt;TR CLASS=”</span>’</p>
<h3>Output, variables and conditions in View CAML</h3>
<p>Next we pick up a variable using the GetVar element. The Name attribute tells SharePoint which variable to get, in this case AlternateStyle. Now, in this example, the first time we enter the ViewBody, which would be for the first list item, this value would be nothing or null since it is a custom variable and we need to set this ourselves. This will happen in this example in a few moments.</p>
<p>Immediately following the GetVar element is a new HTML element which outputs “&gt;. So, for the first item in the list, the HTML output so far would be ‘<span style="#ff0000;">&lt;TR CLASS=””&gt;</span>’.</p>
<p>The IfEqual element that follows is a conditional element. For the IfEqual element we need at least three child elements, the <strong>Expr1</strong>, <strong>Expr2</strong>, and <strong>Then</strong> elements, and we may add an optional <strong>Else</strong> element. The structure is just like a normal conditional element from any other language. We evaluate <strong>Expr1</strong>, compare that to <strong>Expr2</strong> and if these are equal, perform whatever is in <strong>Then</strong>. If the values are not equal and we have an <strong>Else</strong> element, as it the case here, perform whatever is in the <strong>Else</strong> element. If we don’t have a Then element, nothing happens if Expr1 is not equal to Expr2.</p>
<p>Basically, this is the same as writing</p>
<p>if (Expr1 == Expr2) {</p>
<p>&lt;Then&gt;</p>
<p>}</p>
<p>else {</p>
<p>&lt;Else&gt;</p>
<p>}</p>
<p>In our view the Expr1 and Expr2 compares the variable named AlternateStyle to see if it is set to ‘ms-alternating’. If it is, the Then element will set the variable, using the SetVar element, to nothing. Else, meaning the AlternateStyle is already set to nothing, set the AlternateStyle to ‘ms-alternating’ for the scope of this view request. the effect of this is that we alternate for each item whether we output the string ‘ms-alternating’ when we call ‘GetVar Name=”AlternateStyle”’ in line 1505. Or, in plain C#, given that we have a HTMLWriter object called writer, a string called AlternateStyle and an SPList called list:</p>
<p>foreach (SPListItem item in list.Items)<br />
{<br />
writer.Write(&#8220;&lt;TR CLASS=\&#8221;");<br />
writer.Write(AlternateStyle);<br />
writer.Write(&#8220;\&#8221;&gt;&#8221;);<br />
if (AlternateStyle == &#8220;ms-alternating&#8221;)<br />
{<br />
AlternateStyle = &#8220;&#8221;;<br />
}<br />
else<br />
{<br />
AlternateStyle = &#8220;ms-alternating&#8221;;<br />
}</p>
<p>}</p>
<p>The next CAML element is Fields, which starts on line 1520 and ends on line 1541. As for the ViewBody, Fields is called for each Field, or column, in the list item on which we are currently working. We thus start the rendering of each field, or column, by outputting &lt;TD Class=”. Next two FieldSwitch elements, which are just switch conditionals, output either ‘ms-vb-title height=”100%’, ‘ms-vb-icon’, ‘ms-vb-user’, or ‘ms-vb-2’ depending on the ClassInfo property of the field, as well as the Type property and whether Presence is enabled. I won’t go into all the details and recreate a C# statement here, but you should be able to deduce the output. After the switch we output “&gt; to finish the TD we started in line 1520.</p>
<p>However, more importantly, line 1540 outputs the field itself. The logic of exactly what will be output here depends on the field itself, and we’ll get back to that in part 5. For now you can assume that Field outputs the value of the field as it is accurate enough to understand what goes on.</p>
<p>Finally we close the TD html tag we started in line 1520 and, after completing the Fields iteration, close the TR html tag we started in line 1505.</p>
<p>Phew, that was a mouthful, however, the basic concept is that we build HTML for each list item. In this case a TR with a TD for each column. You can, of course, make this a lot simpler if you don’t want or need all the styling and conditions. As such, to just output a TR for each list item and a TD for each column, you might do just:</p>
<p>&lt;ViewBody&gt;<br />
&lt;HTML&gt;&lt;![CDATA[&lt;TD&gt;]]&gt;&lt;/HTML&gt;<br />
&lt;Fields&gt;<br />
&lt;HTML&gt;&lt;![CDATA[&lt;TD&gt;]]&gt;&lt;/HTML&gt;<br />
&lt;Field/&gt;<br />
&lt;HTML&gt;&lt;![CDATA[&lt;/TD&gt;]]&gt;&lt;/HTML&gt;<br />
&lt;/Fields&gt;<br />
&lt;HTML&gt;&lt;![CDATA[&lt;/TR&gt;]]&gt;&lt;/HTML&gt;<br />
&lt;/ViewBody&gt;</p>
<p>which is a lot less complex.</p>
<p>See? Custom view development isn’t really that hard. And if you want to learn more, start by creating your own list template and build views from scratch. There is also a complete chapter in my new book which deals with more advanced concepts of custom view creation, and in my completely unbiased opinion I highly <a href="http://www.understandingsharepoint.com/url/30001" target="_blank">recommend that book</a> to learn CAML view development <img src='http://sharepointmagazine.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h1>Where to now?</h1>
<p>Now that you have seen a bit on how you can use lists to tailor the user experience, you might want to explore a bit further on your own. Here are some resources which might help you along:</p>
<p><a href="http://www.understandingsharepoint.com/url/10031" target="_blank">The MSDN documentation for CAML view schema</a> is the most comprehensive documentation available. You get all the gritty details for all the root elements in a view as well as all the rendering elements. However, be advised that not all aspects of the documentation is as clear as can be, and some information is missing or plain wrong.</p>
<p>If you want a comprehensive guide there is a separate chapter in my book “<a rel="nofollow" href="http://www.understandingsharepoint.com/url/30001" target="_blank">Building the SharePoint User Experience</a>” that covers views and takes you on a guided tour through creating a view using all the aspects of view creation, including sorting, grouping and paging.</p>
<p><a rel="nofollow" href="http://office.microsoft.com/en-us/sharepointdesigner/HA101191111033.aspx" target="_blank">Microsoft Office Online</a> has a nice guide for walking you through setting up a new custom list form page.</p>
<p>And, of course, make sure you read the next part of this series where we will dive into content types and how you can modify appearance of certain types of information.</p>
<p>I do hope I’ll see you again for the future parts of this series,</p>
<p>.b</p>
]]></content:encoded>
			<wfw:commentRss>http://sharepointmagazine.net/technical/development/customizing-the-user-experience-of-sharepoint-lists-custom-list-forms-and-caml-views-part-3-of-6/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SharePoint User Experience Week on SharePoint Magazine</title>
		<link>http://sharepointmagazine.net/announcements/sharepoint-user-experience-week-on-sharepoint-magazine</link>
		<comments>http://sharepointmagazine.net/announcements/sharepoint-user-experience-week-on-sharepoint-magazine#comments</comments>
		<pubDate>Sat, 21 Feb 2009 02:02:59 +0000</pubDate>
		<dc:creator>Arno Nel</dc:creator>
				<category><![CDATA[Announcements]]></category>
		<category><![CDATA[SharePoint Magazine]]></category>
		<category><![CDATA[Bjørn]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[experiance]]></category>
		<category><![CDATA[Furuknap]]></category>
		<category><![CDATA[magazine]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[User]]></category>
		<category><![CDATA[usx]]></category>

		<guid isPermaLink="false">http://sharepointmagazine.net/?p=2664</guid>
		<description><![CDATA[Starting from February 23rd 2009, SharePoint Magazine will hold a user experience week, where all the articles released will focus around the user experience of SharePoint. Every workday, Monday through Friday, Bjørn Furuknap, our resident user experience expert, will release a new article in the Customizing SharePoint User Experience series. These articles are based on [...]]]></description>
			<content:encoded><![CDATA[<p>Starting from February 23rd 2009, <a href="http://sharepointmagazine.net/" target="_blank">SharePoint Magazine</a> will hold a user experience week, where all the articles released will focus around the user experience of SharePoint.</p>
<p>Every workday, Monday through Friday, Bjørn Furuknap, our resident user experience expert, will release a new article in the Customizing SharePoint User Experience series. These articles are based on his book, “<a href="http://www.understandingsharepoint.com/userexperience" target="_blank">Building the SharePoint User Experience</a>”, due for release this April. SharePoint Magazine has secured the exclusive rights to publish previews of the content from this book.</p>
<p>The “<a href="http://sharepointmagazine.net/technical/development/customizing-the-user-experience-of-sharepoint-overview-of-the-default-sharepoint-interface-from-a-technical-point-of-view-part-1-of-6">Customizing the SharePoint User Experience</a>” series has only four articles left. Since there are five days in Bjørn has written a final bonus article, the title and topic of which will be revealed on Thursday’s article.</p>
<p>Stay tuned and you will find out the topic of the bonus article.</p>
]]></content:encoded>
			<wfw:commentRss>http://sharepointmagazine.net/announcements/sharepoint-user-experience-week-on-sharepoint-magazine/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
