RSS Feed

    Social Links


    March 2012 (3)
    February 2012 (2)
    January 2012 (4)
    December 2011 (2)
    October 2011 (4)
    September 2011 (1)
    August 2011 (1)
    June 2011 (2)
    May 2011 (1)
    March 2011 (6)
    February 2011 (3)
    January 2011 (4)
    November 2010 (2)
    October 2010 (2)
    September 2010 (3)
    August 2010 (3)
    July 2010 (4)
    June 2010 (2)
    May 2010 (2)
    March 2010 (5)
    January 2010 (4)
    December 2009 (1)
    November 2009 (3)
    October 2009 (3)
    September 2009 (1)
    August 2009 (3)
    July 2009 (2)
    June 2009 (2)
    May 2009 (1)
    April 2009 (2)
    March 2009 (1)
    January 2009 (1)
    December 2008 (5)
    November 2008 (3)
    October 2008 (5)
    September 2008 (2)
    August 2008 (2)
    July 2008 (1)
    June 2008 (3)
    April 2008 (4)
    March 2008 (4)
    February 2008 (3)
    January 2008 (6)
    December 2007 (8)
    November 2007 (12)
    October 2007 (4)
    September 2007 (3)
    August 2007 (5)
    July 2007 (18)


    Recent Posts

    Other Blogs

    Stefan Goßner
    Tobias Zimmergren's thoughts on development
    Tom Van Rousselt's Blog
    Andrew Connell [MVP SharePoint]
    Chris O'Brien
    IT Pro Ramblings
    Jan Tielens' Bloggings
    JOPX on SharePoint 2007 and SharePoint 2010
    Waldek Mastykarz
    Karine Bosch's Blog
    Mark Harrison 2010
    Michaël's coding thoughts
    Microsoft SharePoint Team Blog
    PDT IT Services Blog Posts
    Tom's Random Ranting
    Sebastian Bouckaert's Blog
    SharePoint Automation
    SharePoint Joel's SharePoint Land
    ]]> RED



    Ellipsis on list item body using jQuery

    October 1, 2009 - 22:35, by Steven Van de Craen
    Categories: Custom Field Types, jQuery/JavaScript, MOSS 2007, Search Server 2008, SharePoint 2007, WSS 3.0, Advanced Computed Field

    A common question to receive is on list items with a long body (eg. Announcements) and then show only X characters and optionally a ‘read more’ link. Many ways to solve this but I went for the following: a Custom Field Type that renders the short text with ellipsis using jQuery.

    This is another example using the Advanced Computed Field in a creative way. The ACF allows you to create computed fields referencing other fields or data in your list and manipulating them through CAML or JavaScript. It has the advantage that this can be done from within the browser, however I admit CAML isn’t the easiest of things to comprehend in the SharePoint technology stack.

    Ellipsis sample

    This ellipsis displays the first 20 characters of the plain text version of the Announcement Body


         <span style="display:none;" id="el_
         <script type="text/javascript">
         { var mySpan = $('#el_
           var myShortText = $(mySpan).text().substring(0, 20); 
           if ($(mySpan).text().length > 20)
             myShortText += '...';

           $(mySpan).show().html(myShortText); });



    Advanced Computed Field

    March 31, 2009 - 21:34, by Steven Van de Craen
    Categories: .NET, SharePoint 2007, Search Server 2008, Custom Field Types, MOSS 2007, WSS 3.0, Advanced Computed Field


    This project originally started as ‘TitleLinkField’ because I needed a way to display the Title field as a hyperlink to the document in a document library, but it ended up being more than just that so I chose a more generic name for it.

    I had some experience with Custom Field Types but event then I spent too many hours (even days) on figuring this one out. It started with standard functionality such as Calculated Field and Computed Field, both having their flaws and limitations. I quickly realised that Custom Field Types might be the only way to tackle the scenario at hand.


    When creating a field based on this type (“Advanced Computed Field”) you need to provide two properties; FieldRefs (MSDN FieldRefs Element (List)) and DisplayPattern (MSDN: DisplayPattern Element (List)). The former requires a list of referenced fields that exist in the collection of our field while the latter contains CAML used for displaying our field. See the MSDN pages on both elements for the schema and possible values.

    What better way than demonstrating by showing ?

    Sample 1: Title linked to document



    Sample 2: Title with ECB






    Sample 3: Random formatting



    You can learn a lot by examining the default fields in a document library or list. A tool such as Stramit SharePoint 2007 Caml Viewer is invaluable here.


    A Custom Field Types derives from a parent class (MSDN: Custom Field Classes). Furthermore you have to define the ParentType field declaratively in the FieldTypes XML definition. It is advised (maybe even required) for them to be the same type.

    Choose the ‘parent class’ that most closely matches your requirements. If you need a ‘text field with regular expression validation’ then go for SPFieldText because that has a lot of textbox relation functionality (especially on the New, Edit and Display Forms).

    The ‘ParentType’ field seems to be the key for CAML related functionality (such as the AllItems View). In my case setting it to “Text” meant that my field didn’t retrieve the values of the referenced fields so it needed to be “Computed”.

    The main issues with the standard Computed Field is that it is invisible from any view; Site Columns, Field in a Content Type, etc. and can only be created declaratively via XML/CAML or through code. Other than these issues the Computed Field did exactly what was needed; render columns in a way that I wanted via the RenderPattern. It turns out that the visibility of a Custom Field Type can be controlled in the declarative XML via the ”ShowOn…” fields.

    For storing and retrieving the DisplayPattern and FieldRefs properties my custom field type exposes two methods that make calls to internal SharePoint methods:

    public void SetInnerXmlForNode(string nodeName, string innerXml)
         Type fldType = this.GetType();
         XmlDocument doc = new XmlDocument();
         doc.LoadXml(String.Format("<{0}>{1}", nodeName, innerXml));

         MethodInfo miSetXml = fldType.GetMethod("SetInnerXmlForNode", BindingFlags.Instance | BindingFlags.NonPublic);
         miSetXml.Invoke(this, new object[] { nodeName, doc.DocumentElement.InnerXml });

    public string GetInnerXmlForNode(string nodeName)
         string result = null;
         Type fldType = this.GetType();

         MethodInfo miGetXml = fldType.GetMethod("GetNodeFromXmlDom", BindingFlags.Instance | BindingFlags.NonPublic);
         XmlNode resultNode = miGetXml.Invoke(this, new object[] { nodeName }) as XmlNode;
         if (resultNode != null)
              StringBuilder sb = new StringBuilder();
              XmlWriterSettings settings = new XmlWriterSettings();
              settings.Indent = true;
              settings.ConformanceLevel = ConformanceLevel.Fragment;
              using (XmlWriter writer = XmlTextWriter.Create(sb, settings))

              result = sb.ToString();
         return result;

    Download and installation

    If you’re interested in reusing or modifying the code feel free to do so. If you just want this installed and available on your SharePoint farm then go for the WSP and deploy via STSADM.

    STSADM -o addsolution -filename VNTG.CustomFieldTypes.AdvancedComputedField.wsp
    STSADM -o deploysolution -name VNTG.CustomFieldTypes.AdvancedComputedField.wsp -allowgacdeployment -immediate -allcontenturls

    Word of caution

    There isn’t a lot of validation on the input of the XML properties. It has to be valid XML but that’s about it. Please follow the schema for FieldRefs and DisplayPattern to make sure you don’t break other functionality. It cannot ‘bring down the farm’ or anything, but it could definitely mess up the rendering of the View.

    Have fun with it !


    View Action Button

    June 20, 2008 - 17:24, by Steven Van de Craen
    Categories: .NET, SharePoint 2007, Custom Field Types


    Don't you just miss the possibility to have buttons on a SharePoint List or Library View similar to an ASP.NET GridView ? You could add Edit or Delete functionality or even cooler things such as navigating to a LAYOUTS page rather than having to use the item context menu drop down:

    I've been playing with Custom Field Types in order to have this kind of functionality and I'm offering the result to you for free !!


    The ViewActionButton Custom Field Type allows you to render a button or hyperlink to a Web Relative Url. The Item ID and List ID are automatically appended for each item so the receiving page can interact with them accordingly.

    Some standard actions include:

    • Workflows: /_layouts/Workflow.aspx?ID=1&List={4F56D0B2-1F4E-46FE-A794-5A6BAAC0CACD}
    • Version History: _layouts/Versions.aspx?list={4F56D0B2-1F4E-46FE-A794-5A6BAAC0CACD}&ID=1

    But you could also provide your own actions via custom LAYOUT pages:

    • Delete item: /_layouts/Vandest/DeleteItem.aspx?ID=1&List={4F56D0B2-1F4E-46FE-A794-5A6BAAC0CACD}
    • Generate PDF: /_layouts/Vandest/GeneratePDF.aspx?ID=1&List={4F56D0B2-1F4E-46FE-A794-5A6BAAC0CACD}

    Once installed you can add as many fields of this type as you want and configure them accordingly:

    • Action URL: The Web Relative Url to a page. The field will automatically append the ListID and ItemID QueryString parameters
    • Format: Specify to render either a button or hyperlink
    • CSS-Class: The CSS class for the rendered item. Use this to further style the button or hyperlink


    Issue #1

    There were several headaches involved with this project. The first one occurred when I found out that the Custom Property mechanism doesn't really work the way it is supposed to. Normally you declare your CustomProperties in the Xml and then use this.SetCustomProperty(name, value) but there's a huge workaround required to make this work:

    I'm not using the workaround described as above but I use the saving mechanism from the out of the box field properties...

    Issue #2

    After that the last remaining obstacle was CAML (Collaborative Application Markup Language). The List View doesn't work with User Controls but requires you to write CAML, HTML and JavaScript and it can be quite scary at first. Good places to start:

    • C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML\FLDTYPES.XML (Take a look at the existing fields how they are rendered)
    • For an overview of CAML Variables go here:
      • Quick Reference:
        • GetVar: can be used in combination with SetVar to store variables on the server.
        • Column: when providing the 'Name' it can be used to get the values of other columns for the item (eg. )
        • Property: get the value of the field property such as name and custom properties (eg. )
        • ListProperty: get the value of the list property (eg. )
        • ProjectProperty: get the value of the web property (eg. )
        • URL: get the URL for a specific Command (eg. )
        • ...
    Invaluable tools and resources


    • SharePoint 2007 Solution (WSP)
    • Visual Studio 2008 Code Solution

    Installation using the WSP should be a breeze using addsolution and deploysolution. It will place the assembly in the GAC and the resource files in the correct location in the 12 hive.


    Feel free to use and improve this :)