Omicron Llama

Coding all day, every day.

SharePoint QuickTip – FileDirRef – Your Friend for a Better User Experience

Quick Tip

When designing your Data View Web Parts, you’ll often have a reference to a specific list Item, or even a specific List.

Give your users an extra helping hand, make things that little bit nicer to use by turning that reference into a hyperlink to that specific List Item or List!

Select the Field itself from the Design view, so that the “Code Breadcrum” at the top of window shows is selected. Jump to code view, and create a hyperlink tag around the value-of tag!

Set the href to a pair of curley braces, and this will “Transform” the href parameter using XSLT. Set the cursor inside the braces, hit CTRL+Space to bring up IntelliSense menu, and select “XPath Expression Builder”.

Pick @FileDirRef and use substring-before or substring-after to get to the information you require.

ie: @FileDirRef will typically return something like this:

1;#TestWeb/SubWeb/Lists/To-Do_List

Use substring-after to get everything after the #, and substring-before with ‘/Lists/’ as a parameter to get everything before /Lists. Use in combination like this:

to get

TestWeb/SubWeb

concat a ‘/’ to the start, like so:

And you’ll have a fully accessibly URL to the site in which the List is located!

Leave a Reply

Your email address will not be published. Required fields are marked *