To get the value of a SharePoint hyperlink field in a custom list using the object model, we generally use.
SPList mylist = myweb.Lists[Your_ListName];
SPQuery rootQuery = new SPQuery();
rootQuery.Query = "";
SPListItemCollection lstitemcol = mylist.GetItems(rootQuery);
rootQuery.Query = "";
SPListItemCollection lstitemcol = mylist.GetItems(rootQuery);
foreach (SPListItem lstitem in lstitemcol)
{
string URL=lstitem[url_Column_Name].ToString();
}
The above URL string will contains the value but the only problem with this URl string is that it will contains two URL’s separated by a comma. This is because one is the actual display text for the field and the other is the value (the actual URL itself).
In order to get just the URL value, you need to use the following object model code:
SPFieldUrlValue rootUrl = new SPFieldUrlValue(lstitem[Column_Name].ToString());
string URL = rootUrl.Url;
You can also use value.Description to get the actual display text for the field.
No comments:
Post a Comment