Thursday 19 January 2012

Outputing the url value of a SharePoint hyperlink field

So as i was working on a SharePoint project i had, i needed to display an image i get from the a hyperlink field inside a repeater.
The problem was that i kept getting the link twice, and i was burning all my brain cell and Google capabilities trying to find a normal solution(parsing the string is not an optimal solution obviously), after a long long search, i came upon this lovely link.
And from there, it was fairly simple, despite my dislike for doing so many unnecessary casting, the end code is as follows:

<img src="<%# (new SPFieldUrlValue(((SPListItem)Container.DataItem)["ChildPicture"].ToString()).Url) %>" alt="ChildPicture" />

No comments:

Post a Comment