Tuesday, March 31, 2009

Adding a title link to an item in a document list

Scenario:
If some one ask me my favorite topic, its CAML , so much can be done with CAML.
I wanted to display document title using a custom field.

Solution:
Field tag support Display pattern.

Code:

<Field ReadOnly="TRUE" Type="Computed" Name="LinkedToTitle"
DisplayName="Document Title" DisplayNameSrcField="Title"
AuthoringInfo="(linked to document)">
<FieldRefs>
<FieldRef Name="Title"/>
<FieldRef Name="FileRef"/>
</FieldRefs>
<DisplayPattern>
<HTML><![CDATA[<A HREF="]]></HTML>
<HttpHost URLEncodeAsURL="TRUE"/>
<LookupColumn Name="FileRef" URLEncodeAsURL="TRUE"/>
<HTML><![CDATA[">]]></HTML>
<Switch>
<Expr>
<Column Name="Title"/>
</Expr>
<Case Value="">
<UrlBaseName HTMLEncode="TRUE">
<LookupColumn Name="FileRef"/>
</UrlBaseName>
</Case>
<Default>
<Column Name="Title" HTMLEncode="TRUE"/>
</Default>
</Switch>
<HTML><![CDATA[</A>]]></HTML>
</DisplayPattern>
</Field>
Article:CAML Viewer

3 comments:

Andy,  April 9, 2009 at 2:11 PM  

I am trying to figure out how to use this. I got it packaged up into a feature... however it doesn't show up as a custom column. Any tips?

GBelzile January 17, 2011 at 9:14 AM  

Couldn't make this work in SP2010, any idea?

Sandeep K Nahta January 17, 2011 at 12:09 PM  

GBelzile.. i need to try for SP2010. I dont see any reason it will not work in SP2010.. but will post update soon