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("<a href=\"{0}/{1}?ID={2}\">{3}</a>", 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"))
Articles & Research
SharePoint Security
SharePoint Development
SharePoint Architecture
Claims Authentication
Forefront For SharePoint
AIS / Dynamics GP
Team Foundation Server
Pex And Moles
ISA/TMG/IAG/UAG
DPM
Cardspace
Research Methodology
Rural ICT Development
Numerical Analysis
Multi-Level Research
Knowledge Management
Personal/Off-Topic
No Comments
Trackbacks/Pingbacks