views:

591

answers:

3

I am adding a new field to a list using the AddFieldAsXML method of SPFieldCollection. The method executes fine with no problem. And the column header shows up when I view the list; however the value never displays in the column. Here is what the field looks like after it has been added to the list. This xml is a snipped from the list schema derived using http://tw-s1-m4400-007:4016/_vti_bin/owssvr.dll?Cmd=ExportList&List={1F87433F-50E1-46C5-A138-00E1CF7E5801}

This code works great in 2007 but does not work in 2010. Any help would be appreciated.

<Field ID="{e24ccb96-35fd-44e5-b7d1-4150dbbc9a64}" Type="Computed" ReadOnly="TRUE"
   Name="My_x0020_Status" DisplayName="MyStatus" ShowInEditForm="TRUE" ClassInfo="Icon"   
AuthoringInfo="(My status)" SourceID="http://schemas.microsoft.com/sharepoint/v3"       
StaticName="MyStatus" FromBaseType="TRUE">  
 <FieldRefs>
  <FieldRef Name="ID" /> 
  <FieldRef Name="Title" /> 
 </FieldRefs>
 <DisplayPattern>
 <HTML>
 <![CDATA[ <a href="form.htm?ID="
  ]]> 
  </HTML>
  <Column Name="ID" /> 
 <HTML>
 <![CDATA[ ">
  ]]> 
  </HTML>
  <Column Name="Title" /> 
 <HTML>
 <![CDATA[ </a>
  ]]> 
  </HTML>
  </DisplayPattern>
</Field>
+1  A: 

This link provided a lot of help in solving this issue:

http://social.technet.microsoft.com/Forums/en/sharepoint2010customization/thread/ef0d1d22-47ff-416c-becd-13d48de80e4d

Basically, display patterns fields are defined in the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\XSL\fldtypes.xsl file.

There is a file called fldtypes_ratings.xsl that you can use as an example of defining your custom field display.

You can create your own xsl file (i.e. fldtypes_myfile.xsl) to define your own custom display.

Here's a sample of my content:

<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" 
xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-
prefixes="xsl msxsl ddwrt" ns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
xmlns:asp="http://schemas.microsoft.com/ASPNET/20" 
xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">

<xsl:template match="FieldRef[@Name='MyCustomField']" mode="Computed_body">
    <xsl:param name="thisNode" select="."/>
      <SPAN class="mystuff-content-item" style="Width:100%;text-align:center">
          <SPAN class='mystuff-socialized-status mystuff-socialized-status-unknown'></SPAN>
          <SPAN class="mystuff-content-object-type" style="display:none">
               MyContent
          </SPAN>
          <SPAN class="mystuff-content-followed" style="display:none">0</SPAN>
          <SPAN class="mystuff-content-name" style="display:none"></SPAN>
          <SPAN class="mystuff-content-id" style="display:none">
            <xsl:value-of select="$List" />
            <xsl:text>|</xsl:text>
            <xsl:value-of select="$thisNode/@ID" />
          </SPAN>
      </SPAN>
    </xsl:template>

</xsl:stylesheet>

Hope that helps!

A: 

This is also documented in the SDK:

http://msdn.microsoft.com/en-us/library/ff606773(v=office.14).aspx

RK
A: 

This method of customization from 2007 is made obselete by changes in 2010's rendering of fields. Read the note from the SDK entry on RenderPattern for more detail:

Important! This topic describes markup that was used in a now obsolete method of rendering custom fields types on list views and on the Display, Edit, and New forms. It is provided solely to assist persons who are debugging a custom field type that was originally developed against an earlier version of SharePoint Foundation. For information about the recommended methods, see How to: Create Field Rendering Templates and How to: Create a Custom Field Type. Custom fields whose rendering is defined with RenderPattern markup still render properly on forms. However, SharePoint Foundation, by default, uses XSLT stylesheets to render fields on list views, even for legacy custom fields whose list view rendering is defined with a RenderPattern. To enable the rendering of such a field, a TRUE element must be added to the containing FieldTypes element in the field type definition file (fldtype*.xml).

Tom Resing

related questions