<?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/"
	>

<channel>
	<title>Dev Team Assemble &#187; xml</title>
	<atom:link href="http://www.calvinirwin.net/tag/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.calvinirwin.net</link>
	<description>Evil beware!</description>
	<lastBuildDate>Mon, 06 Feb 2012 18:42:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>XmlSerializer and XmlRootAttribute Performance Issue</title>
		<link>http://www.calvinirwin.net/2011/02/10/xmlserializer-and-xmlrootattribute-performance-issue/</link>
		<comments>http://www.calvinirwin.net/2011/02/10/xmlserializer-and-xmlrootattribute-performance-issue/#comments</comments>
		<pubDate>Fri, 11 Feb 2011 03:28:52 +0000</pubDate>
		<dc:creator>Calvin</dc:creator>
				<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c sharp]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[serialization]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[XmlSerializer]]></category>

		<guid isPermaLink="false">http://www.calvinirwin.net/?p=262</guid>
		<description><![CDATA[I have been working with xml serialization over the last week or so and ran into a strange issue today.  It only came to light when I decided to implement IXmlSerializable and write my own methods for reading and writing the xml.  I posted recently about using he XmlRootAttribute as a fix for [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working with xml serialization over the last week or so and ran into a strange issue today.  It only came to light when I decided to implement IXmlSerializable and write my own methods for reading and writing the xml.  I <a href="http://www.calvinirwin.net/2011/02/10/xmlserialization-deserialize-causes-xmlns-was-not-expected/">posted</a> recently about using he XmlRootAttribute as a fix for the <a href="http://www.calvinirwin.net/2011/02/10/xmlserialization-deserialize-causes-xmlns-was-not-expected/">xmlns='' &gt; was not expected</a> error I was seeing.  This all worked fine and dandy until I really started to utilize that method over and over again in my code.  I found the performance of this to be horrible...so horrible in fact it was taking 2-3 minutes to deserialize a moderately complex 1MB xml file.  After doing some digging (on "The Google") I discovered that microsoft decided to only implement caching on the Xml serializer when you use one of the two "more common" constructors (see <a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx">documentation</a>).  Of course it would seem the one I need would not be one of them.</p>
<p>I was thinking of somehow adding the XmlSerializers for each type/root pair that I was using to the application level cache or something like that but thought that might bring with it its own set of challenges.  I found a <a href="http://stackoverflow.com/questions/1534810/xmlserializer-performance-issue-when-specifying-xmlrootattribute">great article here on stack overflow</a> that shows a possible workaround for the problem using a static class to act as a cache or you.</p>
<p>Please note this code is taken directly from the article above:</p>
<p><code><br />
public static class XmlSerializerCache<br />
{<br />
     private static readonly Dictionary cache =<br />
     new Dictionary();</code></p>
<p><code>     public static XmlSerializer Create(Type type, XmlRootAttribute root)<br />
     {<br />
          var key = String.Format( CultureInfo.InvariantCulture, "{0}:{1}", type, root.ElementName);</p>
<p>          if (!cache.ContainsKey(key))<br />
          {<br />
               cache.Add(key, new XmlSerializer(type, root));<br />
          }<br />
</code><br />
<code>           return cache[key];<br />
     }<br />
}<br />
</code></p>
<p>Here is how you use it to create an XmlSerializer object:</p>
<p><code><br />
var xmlRootAttribute = new XmlRootAttribute("ExampleElement");<br />
var serializer = XmlSerializerCache.Create(target.GetType(), xmlRootAttribute);<br />
</code></p>
<p>After implementing that I was still experiencing the 2-3 minute deserialization one the first call but all subsequent calls to that code with similar xml took only 2 seconds.</p>
<p><strong>NOTE:</strong><br />
<em>Seems microsoft is in the habit of only half implementing caching in their code.  This problem is almost identical to the problems with the CrossListQueryCache object in SharePoint....where they again only implemented caching for two of the four available method signatures.  Here is an <a href="http://connect.microsoft.com/VisualStudio/feedback/details/98384/xmlserializer-memory-leak">interesting article</a> I found in the nether-regions of cyberspace where microsoft state this half implementation is by design...</em></p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/.net' rel='tag' target='_self'>.net</a>, <a class='technorati-link' href='http://technorati.com/tag/ASP.NET' rel='tag' target='_self'>ASP.NET</a>, <a class='technorati-link' href='http://technorati.com/tag/c+sharp' rel='tag' target='_self'>c sharp</a>, <a class='technorati-link' href='http://technorati.com/tag/c%23' rel='tag' target='_self'>c#</a>, <a class='technorati-link' href='http://technorati.com/tag/Development' rel='tag' target='_self'>Development</a>, <a class='technorati-link' href='http://technorati.com/tag/serialization' rel='tag' target='_self'>serialization</a>, <a class='technorati-link' href='http://technorati.com/tag/xml' rel='tag' target='_self'>xml</a>, <a class='technorati-link' href='http://technorati.com/tag/XmlSerializer' rel='tag' target='_self'>XmlSerializer</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.calvinirwin.net/2011/02/10/xmlserializer-and-xmlrootattribute-performance-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XmlSerialization Deserialize causes xmlns=&#8221; was not expected</title>
		<link>http://www.calvinirwin.net/2011/02/10/xmlserialization-deserialize-causes-xmlns-was-not-expected/</link>
		<comments>http://www.calvinirwin.net/2011/02/10/xmlserialization-deserialize-causes-xmlns-was-not-expected/#comments</comments>
		<pubDate>Fri, 11 Feb 2011 02:48:40 +0000</pubDate>
		<dc:creator>Calvin</dc:creator>
				<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c sharp]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[XmlSerializer]]></category>

		<guid isPermaLink="false">http://www.calvinirwin.net/?p=264</guid>
		<description><![CDATA[I had what turns out to be a fairly common error the other day when trying to deserialize an xml file in one of my applications.  Here is the code I was running:

XmlSerializer ser =  new XmlSerializer(typeof(MyObject));
XmlReader xRdr = XmlReader.Create(new StringReader(xmlData));
MyObject tvd = (MyObject)ser.Deserialize(xRdr);

As it turns out this was causing the error: xmlns=''&#62; was [...]]]></description>
			<content:encoded><![CDATA[<p>I had what turns out to be a fairly common error the other day when trying to deserialize an xml file in one of my applications.  Here is the code I was running:</p>
<p><code><br />
XmlSerializer ser =  new XmlSerializer(typeof(MyObject));<br />
XmlReader xRdr = XmlReader.Create(new StringReader(xmlData));<br />
MyObject tvd = (MyObject)ser.Deserialize(xRdr);<br />
</code></p>
<p>As it turns out this was causing the error: <strong>xmlns=''&gt; was not expected </strong> during deserialization.  Alot of the resources online (including the <a href="http://msdn.microsoft.com/en-us/library/aa302290.aspx">msdn article here</a>) were pointing me to the namespaces not being the same on the serializer and document.  I am not sure why it wasn't working for me because I was playing around with the namespaces but couldn't seem to figure out how to get that working.  Maybe because I was only serializing a fragment of a document I'm not sure.  Anyway it turns out that specifying the XmlRootAttribute in the XmlSerializer constructor fixed the problem for me.  This <a href="http://stackoverflow.com/questions/1556874/user-xmlns-was-not-expected-deserializing-twitter-xml">Stack Overflow article</a> really helped  Here is the snippet of code that I am using now:</p>
<p><code><br />
XmlRootAttribute xRoot = new XmlRootAttribute();<br />
xRoot.ElementName = elementName;<br />
xRoot.IsNullable = true;</code></p>
<p><code> </code></p>
<p><code>XmlSerializer ser =  new XmlSerializer(typeof(MyObject), xRoot);<br />
XmlReader xRdr = XmlReader.Create(new StringReader(xmlData));<br />
MyObject tvd = (MyObject)ser.Deserialize(xRdr);<br />
</code></p>
<p>Hope this helps</p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/.net' rel='tag' target='_self'>.net</a>, <a class='technorati-link' href='http://technorati.com/tag/ASP.NET' rel='tag' target='_self'>ASP.NET</a>, <a class='technorati-link' href='http://technorati.com/tag/c+sharp' rel='tag' target='_self'>c sharp</a>, <a class='technorati-link' href='http://technorati.com/tag/c%23' rel='tag' target='_self'>c#</a>, <a class='technorati-link' href='http://technorati.com/tag/xml' rel='tag' target='_self'>xml</a>, <a class='technorati-link' href='http://technorati.com/tag/XmlSerializer' rel='tag' target='_self'>XmlSerializer</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.calvinirwin.net/2011/02/10/xmlserialization-deserialize-causes-xmlns-was-not-expected/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Custom Field Types&#8230;Building a base XML Field Type for SharePoint</title>
		<link>http://www.calvinirwin.net/2009/08/12/custom-field-types-seriously/</link>
		<comments>http://www.calvinirwin.net/2009/08/12/custom-field-types-seriously/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 23:47:10 +0000</pubDate>
		<dc:creator>Calvin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[controls]]></category>
		<category><![CDATA[custom field type]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.calvinirwin.net/?p=124</guid>
		<description><![CDATA[Sometimes when I am working with SharePoint I really feel like I got it.  You now that feeling you get when you know exactly what you are doing and have no problems implementing it...then there are times when I really just want to smash something.  And it really doesn't matter what...it could be anything!  This [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes when I am working with SharePoint I really feel like I got it.  You now that feeling you get when you know exactly what you are doing and have no problems implementing it...then there are times when I really just want to smash something.  And it really doesn't matter what...it could be anything!  This is the feeling I got in the last couple of days working with custom field types in SharePoint.</p>
<p>It seems there are lots of blogs and articles out there talking about how to do it, but from what I could see (and to be fair I did not read them all so if you know of some good posts that would be great) it felt like most of the time I was only getting half the story.  I just finished putting together a very basic Custom Field Type that will display a multi line textbox in edit/new mode and simply display the value in a literal control in display mode.  In the grand scheme of things I am building a base XML Field Type to use for a series of additional Custom field types so essentially I want to store a string (yes I could use the XmlDocument)...but alas thats a story for another day.</p>
<p>So a bit of a primer, or rehash so I don't forget, when developing custom field types there are many pieces to it....not all of them required.  Here is a list of the items and what they do:</p>
<ul>
<li><strong>Field Type class </strong>- this class acts as the controller and hooks the rendering control, field type xml definition and the value class together.  It also provides validation at the field level via the GetValidatedString() method of the SPField object</li>
<li> <strong>Field Control class</strong> - this is the rendering engine and gives you the power to display your control in any manner you wish as well as perform validation on the data being saved via the UI.</li>
<li><strong>Field Value class</strong> - allows for custom logic to be put around mutiple column fields and different data structures that will be storing data for your field type.</li>
<li><strong>.ascx file in CONTROLTEMPLATES directory</strong> - this supplies rendering markup via a user control and hooks into the field control class</li>
<li><strong>fldtypes_*</strong> - this file that gets installed into the 12/TEMPLATES/XML directory and contains the information that SharePoint requires in order to load your field type into the system.  Such as the assembly to use, the parent type and other information.  This is required if the type is going to be applied to content types and become a field on a list.</li>
</ul>
<p>So for my requirements I only needed the field type, the field control and the fldtypes_xxx.xml file.  Lets look at the field type class I built</p>
<pre class="csharp"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> XmlFieldType : SPField
   <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> XmlFieldType<span style="color: #000000;">&#40;</span>SPFieldCollection fields, <span style="color: #FF0000;">string</span> fieldName<span style="color: #000000;">&#41;</span> : <span style="color: #0600FF;">base</span><span style="color: #000000;">&#40;</span>fields, fieldName<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> XmlFieldType<span style="color: #000000;">&#40;</span>SPFieldCollection fields, <span style="color: #FF0000;">string</span> fieldName, <span style="color: #FF0000;">string</span> displayName<span style="color: #000000;">&#41;</span> : <span style="color: #0600FF;">base</span><span style="color: #000000;">&#40;</span>fields, fieldName, displayName<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> BaseFieldControl FieldRenderingControl
        <span style="color: #000000;">&#123;</span>
            get
            <span style="color: #000000;">&#123;</span>
                BaseFieldControl fldControl = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> XmlFieldControl<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
                fldControl.<span style="color: #0000FF;">FieldName</span> = InternalName;
                <span style="color: #0600FF;">return</span> fldControl;
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">object</span> GetFieldValue<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> value<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>value<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">null</span>;
            <span style="color: #0600FF;">return</span> value;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> Type FieldValueType
        <span style="color: #000000;">&#123;</span>
            get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>; <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">string</span> DefaultValue
        <span style="color: #000000;">&#123;</span>
            get
            <span style="color: #000000;">&#123;</span>
                XmlDocument doc = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> XmlDocument<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
                doc.<span style="color: #0000FF;">LoadXml</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">SchemaXml</span><span style="color: #000000;">&#41;</span>;
                XmlNode nodeInFieldSchema = doc.<span style="color: #0000FF;">SelectSingleNode</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Field/Default&quot;</span><span style="color: #000000;">&#41;</span>;
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>nodeInFieldSchema != <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #0600FF;">return</span> nodeInFieldSchema.<span style="color: #0000FF;">InnerXml</span>;
                <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">null</span>;
            <span style="color: #000000;">&#125;</span>
            set <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">DefaultValue</span> = value; <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">string</span> GetValidatedString<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> value<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">GetValidatedString</span><span style="color: #000000;">&#40;</span>value<span style="color: #000000;">&#41;</span>;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>value == <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Required</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SPFieldValidationException<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Invalid value for required field.&quot;</span><span style="color: #000000;">&#41;</span>;
                <span style="color: #0600FF;">return</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Empty</span>;
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">else</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> value.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre>
<p>Lets review</p>
<ul>
<li>The two constructors are required...don't even bother</li>
<li><strong>FieldRenderingControl()</strong> method tells the field type which control to use</li>
<li><strong>GetFieldValue()</strong> method returns the value of the field....if we were using a custom type you would cast that to the appropriate type here</li>
<li><strong>FieldValueType()</strong> - get the type of the Value class</li>
<li><strong>DefautValue()</strong> - this gets the default value from the field if one is defined</li>
<li><strong>GetValidatedString()</strong> - perform field level validation</li>
</ul>
<p>The Field Control Class is fairly simple as well:</p>
<pre class="csharp"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> XmlFieldControl : BaseFieldControl
<span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">protected</span> Literal _values;
        <span style="color: #0600FF;">protected</span> TextBox _editor;
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnInit<span style="color: #000000;">&#40;</span>EventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">OnInit</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span>;
            EnsureChildControls<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> CreateChildControls<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Field</span> == <span style="color: #0600FF;">null</span> || <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">ControlMode</span> == SPControlMode.<span style="color: #0000FF;">Invalid</span><span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">return</span>;
&nbsp;
            Controls.<span style="color: #0000FF;">Clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">CreateChildControls</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            _editor = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> TextBox<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            _editor.<span style="color: #0000FF;">TextMode</span> = TextBoxMode.<span style="color: #0000FF;">MultiLine</span>;
            _editor.<span style="color: #0000FF;">Height</span> = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Unit<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">300</span><span style="color: #000000;">&#41;</span>;
            _editor.<span style="color: #0000FF;">Width</span> = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Unit<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">500</span><span style="color: #000000;">&#41;</span>;
            Controls.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>_editor<span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>ControlMode == SPControlMode.<span style="color: #0000FF;">Display</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                _values = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Literal<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
                _values.<span style="color: #0000FF;">Text</span> = Convert.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span>ItemFieldValue<span style="color: #000000;">&#41;</span>;
                Controls.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>_values<span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> Render<span style="color: #000000;">&#40;</span>HtmlTextWriter output<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
&nbsp;
            EnsureChildControls<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>ControlMode == SPControlMode.<span style="color: #0000FF;">Display</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_values != <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                    _values.<span style="color: #0000FF;">RenderControl</span><span style="color: #000000;">&#40;</span>output<span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">else</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_editor != <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                    _editor.<span style="color: #0000FF;">RenderControl</span><span style="color: #000000;">&#40;</span>output<span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">virtual</span> <span style="color: #FF0000;">string</span> Text
        <span style="color: #000000;">&#123;</span>
            get
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">EnsureChildControls</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>._editor == <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">null</span>;
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>._editor.<span style="color: #0000FF;">Text</span>;
            <span style="color: #000000;">&#125;</span>
&nbsp;
            set
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">EnsureChildControls</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>._editor != <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">this</span>._editor.<span style="color: #0000FF;">Text</span> = value;
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">object</span> Value
        <span style="color: #000000;">&#123;</span>
            get
            <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Text</span>; <span style="color: #000000;">&#125;</span>
            set
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">Field</span> != <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Text</span> = <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">Field</span>.<span style="color: #0000FF;">GetFieldValueForEdit</span><span style="color: #000000;">&#40;</span>value<span style="color: #000000;">&#41;</span>;
                    <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">Value</span> = <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>value;
                    <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">UpdateFieldValueInItem</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span></pre>
<p>Lets take a look at what this class is doing:</p>
<ul>
<li><strong>OnInit()</strong> - come on, do I have to explain?</li>
<li><strong>CreateChildControls() </strong>- initialize your controls and add to the Controls collection</li>
<li><strong>Render()</strong> - writes the controls to the HtmlTextWriter</li>
<li><strong>Text</strong> - This sets/gets the value in the controls</li>
<li><strong>Value</strong> - this sets the value in the Text property and notice the <strong>base.UpdateFieldValueInItem();</strong> statement...this oushes the value from Value to ItemFieldValue and allows you to access this value in display mode because Value returns null (which i did not find the documentation on M$ thank you very much).</li>
</ul>
<p>So that leaves the last piece of the pie for my simple implementation the fldtypes file:</p>
<pre class="xml"><span style="color: #ddbb00;">&amp;lt;</span>FieldTypes<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>FieldType<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>Field Name=&quot;TypeName&quot;<span style="color: #ddbb00;">&amp;gt;</span>XmlFieldType<span style="color: #ddbb00;">&amp;lt;</span>/Field<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>Field Name=&quot;ParentType&quot;<span style="color: #ddbb00;">&amp;gt;</span><span style="color: #ddbb00;">&amp;lt;</span>/Field<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>Field Name=&quot;InternalType&quot;<span style="color: #ddbb00;">&amp;gt;</span>Note<span style="color: #ddbb00;">&amp;lt;</span>/Field<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>Field Name=&quot;SQLType&quot;<span style="color: #ddbb00;">&amp;gt;</span>ntext<span style="color: #ddbb00;">&amp;lt;</span>/Field<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>Field Name=&quot;TypeDisplayName&quot;<span style="color: #ddbb00;">&amp;gt;</span>Xml Field<span style="color: #ddbb00;">&amp;lt;</span>/Field<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>Field Name=&quot;TypeShortDescription&quot;<span style="color: #ddbb00;">&amp;gt;</span>Xml controls<span style="color: #ddbb00;">&amp;lt;</span>/Field<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>Field Name=&quot;UserCreatable&quot;<span style="color: #ddbb00;">&amp;gt;</span>TRUE<span style="color: #ddbb00;">&amp;lt;</span>/Field<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>Field Name=&quot;ShowOnListCreate&quot;<span style="color: #ddbb00;">&amp;gt;</span>TRUE<span style="color: #ddbb00;">&amp;lt;</span>/Field<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>Field Name=&quot;Sortable&quot;<span style="color: #ddbb00;">&amp;gt;</span>FALSE<span style="color: #ddbb00;">&amp;lt;</span>/Field<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>Field Name=&quot;AllowBaseTypeRendering&quot;<span style="color: #ddbb00;">&amp;gt;</span>FALSE<span style="color: #ddbb00;">&amp;lt;</span>/Field<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>Field Name=&quot;Filterable&quot;<span style="color: #ddbb00;">&amp;gt;</span>FALSE<span style="color: #ddbb00;">&amp;lt;</span>/Field<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>Field Name=&quot;FieldTypeClass&quot;<span style="color: #ddbb00;">&amp;gt;</span>Website.CustomFields.XmlFieldType, Website.CustomFields, Version=1.0.0.0, Culture=neutral, PublicKeyToken=346fcdd567259ee6<span style="color: #ddbb00;">&amp;lt;</span>/Field<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>RenderPattern Name=&quot;HeaderPattern&quot;<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>Property Select=&quot;DisplayName&quot; HTMLEncode=&quot;TRUE&quot;/<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>/RenderPattern<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>RenderPattern Name=&quot;DisplayPattern&quot;<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>Column/<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>/RenderPattern<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>/FieldType<span style="color: #ddbb00;">&amp;gt;</span>
<span style="color: #ddbb00;">&amp;lt;</span>/FieldTypes<span style="color: #ddbb00;">&amp;gt;</span></pre>
<p>So there you have it.  All I need to do in order to inherit from this is to remove the rendering (which i dont need anyway  as this is going to be a base type) and it should be good to go.  Those three pieces of code can be installed into your SharePoint environment and should help you get started to understanding custom field types.</p>
<p><span style="color: #800000;"><em>Don't forget to add the SafeControl entry, Adjust your trust level and move the .dll into your bin folder as well.</em></span></p>
<p><a href="/files/FieldType.zip">Download the code here</a></p>
<p>Resources I found useful:</p>
<ul>
<li>I did work through the example in <a href="http://www.andrewconnell.com/blog/">Andrew Connell</a>'s book (Professional SP 2007 WCM development) and that worked fine and he actually does a great job of explaining most of whats going on here.</li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms446361.aspx">MSDN</a>...where else</li>
<li><a href="http://www.chaholl.com/archive/2009/07/18/custom-fieldtypes-ndash-part-1.aspx">Charlie Holland </a>has a pretty good article series on this stuff but unfortunately I couldn't get it working.  I also wanted a simple bare bones implementation.</li>
</ul>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 2968px; width: 1px; height: 1px;">Sometimes when I am working with SharePoint I really feel like I got it.  You now that feeling you get when you know exactly what you are doing and have no problems implementing it...then there are times when I really just want to smash something.  And it really doesn't matter what...it could be anything!  This is the feeling I got in the last couple of days working with custom field types in SharePoint.  It seems there are lots of blogs and articles out there talking about how to do it, but from what I could see (and to be fair I did not read them all so if you know of some good posts that would be great) it felt like most of the time I was only getting half the story.  I just finished putting together a very basic Custom Field Type that will display a multiline textbox in edit/new mode and simply display the value in a literal control in display mode.  In the grand scheme of things I am building a base XML Field Type to use for a series of additional Custom field types so essentially I want to store a string (yes I could use the XmlDocument)...but alas thats a story for another day.</p>
<p>So a bit of a primer, or rehash so I don't forget, when developing custom field types there are many pieces to it....not all of them required.  Here is a lit of the items and what they do:</p>
<p>* Field Type class - this class acts as the controller and hooks the rendering control, field type xml definition and the value class together.  It also provides validation at the field level via the GetValidatedString() method of the SPField object<br />
* Field Control class - this is the rendering engine and gives you the power to display your control in any manner you wish as well as perform validation on the data being saved via the UI.<br />
* Field Value class - allows for custom logic to be put around mutiple column fields and different data structures that will be storing data for your field type.<br />
* .ascx file in CONTROLTEMPALTES directory - this supplies rendering markup via a usercontrol and hooks into the field control class<br />
* fldtypes_* - this file that gets installed into the 12/TEMPLATES/XML directory and contrains the information that SharePoint requires in order to load your field type into the system.  Such as the assembly to use, the parent type and other information.  This is required if the type is going to be applied to content types and become a field on a list.</p>
<p>So for my requirements I only needed the field type, the field control and the fldtypes_xxx.xml file.  Lets look at the field type class I built</p>
<pre class="csharp"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> XmlFieldType : SPField
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">public</span> XmlFieldType<span style="color: #000000;">&#40;</span>SPFieldCollection fields, <span style="color: #FF0000;">string</span> fieldName<span style="color: #000000;">&#41;</span> : <span style="color: #0600FF;">base</span><span style="color: #000000;">&#40;</span>fields, fieldName<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">public</span> XmlFieldType<span style="color: #000000;">&#40;</span>SPFieldCollection fields, <span style="color: #FF0000;">string</span> fieldName, <span style="color: #FF0000;">string</span> displayName<span style="color: #000000;">&#41;</span> : <span style="color: #0600FF;">base</span><span style="color: #000000;">&#40;</span>fields, fieldName, displayName<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> BaseFieldControl FieldRenderingControl
<span style="color: #000000;">&#123;</span>
get
<span style="color: #000000;">&#123;</span>
BaseFieldControl fldControl = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> XmlFieldControl<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
fldControl.<span style="color: #0000FF;">FieldName</span> = InternalName;
<span style="color: #0600FF;">return</span> fldControl;
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">object</span> GetFieldValue<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> value<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>value<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">return</span> <span style="color: #0600FF;">null</span>;
<span style="color: #0600FF;">return</span> value;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> Type FieldValueType
<span style="color: #000000;">&#123;</span>
get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> <a href="http://www.google.com/search?q=typeof+msdn.microsoft.com"><span style="color: #008000;">typeof</span></a><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>; <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">string</span> DefaultValue
<span style="color: #000000;">&#123;</span>
get
<span style="color: #000000;">&#123;</span>
XmlDocument doc = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> XmlDocument<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
doc.<span style="color: #0000FF;">LoadXml</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">SchemaXml</span><span style="color: #000000;">&#41;</span>;
XmlNode nodeInFieldSchema = doc.<span style="color: #0000FF;">SelectSingleNode</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Field/Default&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>nodeInFieldSchema != <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">return</span> nodeInFieldSchema.<span style="color: #0000FF;">InnerXml</span>;
<span style="color: #0600FF;">return</span> <span style="color: #0600FF;">null</span>;
<span style="color: #000000;">&#125;</span>
set <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">DefaultValue</span> = value; <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">string</span> GetValidatedString<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> value<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">GetValidatedString</span><span style="color: #000000;">&#40;</span>value<span style="color: #000000;">&#41;</span>;
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>value == <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Required</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SPFieldValidationException<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Invalid value for required field.&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #0600FF;">return</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Empty</span>;
<span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">else</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">return</span> value.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre>
<p>Lets review</p>
<p>* The two constructors are required<br />
* FieldRenderingControl() method tells the field type which control to use<br />
* GetFieldValue() method returns the value of the field....if we were using a custom type you would cast that to the appropriate type here<br />
* FieldValueType() - get the type of the Value class<br />
* DefautValue() - this gets the default value from the field if one is defined<br />
* GetValidatedString() - perform field level validation</p>
<p>The Field Control Class is fairly simple as well:</p>
<pre class="csharp"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> XmlFieldControl : BaseFieldControl
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">protected</span> Literal _values;
<span style="color: #0600FF;">protected</span> TextBox _editor;
&nbsp;
<span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnInit<span style="color: #000000;">&#40;</span>EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">OnInit</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span>;
EnsureChildControls<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> CreateChildControls<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Field</span> == <span style="color: #0600FF;">null</span> || <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">ControlMode</span> == SPControlMode.<span style="color: #0000FF;">Invalid</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">return</span>;
&nbsp;
Controls.<span style="color: #0000FF;">Clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">CreateChildControls</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
_editor = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> TextBox<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
_editor.<span style="color: #0000FF;">TextMode</span> = TextBoxMode.<span style="color: #0000FF;">MultiLine</span>;
_editor.<span style="color: #0000FF;">Height</span> = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Unit<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">300</span><span style="color: #000000;">&#41;</span>;
_editor.<span style="color: #0000FF;">Width</span> = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Unit<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">500</span><span style="color: #000000;">&#41;</span>;
Controls.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>_editor<span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>ControlMode == SPControlMode.<span style="color: #0000FF;">Display</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
_values = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Literal<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
_values.<span style="color: #0000FF;">Text</span> = Convert.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span>ItemFieldValue<span style="color: #000000;">&#41;</span>;
Controls.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>_values<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> Render<span style="color: #000000;">&#40;</span>HtmlTextWriter output<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
&nbsp;
EnsureChildControls<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>ControlMode == SPControlMode.<span style="color: #0000FF;">Display</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_values != <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
_values.<span style="color: #0000FF;">RenderControl</span><span style="color: #000000;">&#40;</span>output<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">else</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_editor != <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
_editor.<span style="color: #0000FF;">RenderControl</span><span style="color: #000000;">&#40;</span>output<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">virtual</span> <span style="color: #FF0000;">string</span> Text
<span style="color: #000000;">&#123;</span>
get
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">EnsureChildControls</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>._editor == <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">return</span> <span style="color: #0600FF;">null</span>;
<span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>._editor.<span style="color: #0000FF;">Text</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
set
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">EnsureChildControls</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>._editor != <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">this</span>._editor.<span style="color: #0000FF;">Text</span> = value;
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">object</span> Value
<span style="color: #000000;">&#123;</span>
get
<span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Text</span>; <span style="color: #000000;">&#125;</span>
set
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">Field</span> != <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Text</span> = <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">Field</span>.<span style="color: #0000FF;">GetFieldValueForEdit</span><span style="color: #000000;">&#40;</span>value<span style="color: #000000;">&#41;</span>;
<span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">Value</span> = <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span>value;
<span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">UpdateFieldValueInItem</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre>
<p>sdfsdf</p>
<pre class="xml">    XmlFieldType
&nbsp;
    Note
    ntext
    Xml Field
    Xml controls
    TRUE
    TRUE
    FALSE
    FALSE
    FALSE
    Website.CustomFields.XmlFieldType, Website.CustomFields, Version=1.0.0.0, Culture=neutral, PublicKeyToken=346fcdd567259ee6</pre>
<p>I did work through the example in Andrew Connell's book (Professional SP 2007 WCM development) and that worked fine and he actually does a great job of explaining most of whats going on here.</p>
<p>http://msdn.microsoft.com/en-us/library/ms446361.aspx</p></div>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/controls' rel='tag' target='_self'>controls</a>, <a class='technorati-link' href='http://technorati.com/tag/custom+field+type' rel='tag' target='_self'>custom field type</a>, <a class='technorati-link' href='http://technorati.com/tag/Development' rel='tag' target='_self'>Development</a>, <a class='technorati-link' href='http://technorati.com/tag/SharePoint' rel='tag' target='_self'>SharePoint</a>, <a class='technorati-link' href='http://technorati.com/tag/xml' rel='tag' target='_self'>xml</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.calvinirwin.net/2009/08/12/custom-field-types-seriously/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

