开发者

Retrieving a url (or any value) from SPList

I just spent half an hour trying to figure out how to retrieve a link from SPList.

I have a column of type "Hyperlink or Picture" in开发者_StackOverflow a list, and so far I came up with this:

SPListItem item = /* init item here */
SPFieldUrl field = item.Fields["URL"] as SPFieldUrl;
SPFieldUrlValue urlValue = field.GetFieldValue(item["URL"].ToString()) as SPFieldUrlValue;
string url = urlValue.Url;

This is ugly, though - is there a better way ?


Try getting the value directly from the item rather than converting it. Example:

SPListItem item = //whatever
string url = item["URL"].ToString();


Found a tad cleaner way:

SPListItem item = /* init item here */
string url = new SPFieldUrlValue(item["URL"].ToString()).Url;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜