Remember To Encode SharePoint Link* Fields Correctly

When using a SPGridView control or a similar interface control representing fields out of a SharePoint list, it is important to remember that the SharePoint Link* fields are encoded correctly. Most other types when using something like SPListItem.GetFormattedValue will be fine, but when LinkTitle, LinkDiscussionTitle, etc. are hit you can use something like the below to HTML encode it.

string.Format(“{3}“, SPListItem.Web.Url, SPListItem.ParentList.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url, SPListItem.ID, SPListItem.GetFormattedValue(SPField.InternalName));

To test the type just use , then employ an equality test:

if (Equals(SPListItem.GetFormattedValue(SPField.InternalName), “LinkTitle”))


No Comments


  1. Links (9/10/2009) « Steve Pietrek – Everything SharePoint - [...] Remember To Encode SharePoint Link* Fields Correctly [...]

Leave a Reply

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