SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I got a hyperlink column in my list. Then i got a search to the list and when it shows the answer in a textbox i get duplicate. Lets say, i'm saving to the list, but when i get the answer after searching in the list it shows . any solutions?

Code in my search button:

    protected void ButtonChoose_Click(object sender, EventArgs e)
            using (SPSite site = new SPSite("http://knowitintranet:9797/sites/News"))
                LabelAuthor.Text = string.Empty;
                LabelShowTitle.Text = string.Empty;
                LabelShowDate.Text = string.Empty;
                LabelContent.Text = string.Empty;
                LabelLinks.Text = string.Empty;

                SPWeb web = SPContext.Current.Web;
                SPList list = web.Lists.TryGetList(DropDownListCategory2.SelectedItem.Value);

                SPListItemCollection items = list.GetItems();

                foreach (SPListItem item in items)
                    LabelShowTitle.Text = item["Title"].ToString();
                    LabelAuthor.Text = item["Authors"].ToString();
                    LabelContent.Text = item["Contents"].ToString();
                    LabelLinks.Text = item["Links"].ToString();
                    LabelShowDate.Text = item["Date"].ToString();

        catch (Exception x)
            LabelException.Text = x.Message;
share|improve this question
up vote 4 down vote accepted

That's because a hyperlink column saves 2 values; Link itself, link description.

If link description is not filled out when creating a new item it will automatically copy the URL from the URL field down to the description field and thus return both when requested.

This can be solved by converting item["Links] to a SPFieldUrlValue field:

LabelLinks.Text = new SPFieldUrlValue(item["Links"].ToString()).Url;
share|improve this answer
When changing LabelLinks.Text = item["Links"].ToString(); to LabelLinks.Text = SPFieldUrlValue(item["Links"].ToString()).Url; i get an error: "Method, delegate or event is expected" – Kristian Salov Jan 22 '13 at 8:58
@Kriistiian I forgot that it should new SPFieldUrlValue... instead of just SPFieldUrlValue.... My bad. – Daniel Ziga Jan 22 '13 at 9:06
This one solved my problem. Thank you very much, thumbs up. – Kristian Salov Jan 22 '13 at 9:19
Changed LabelLinks.Text = item["Links"].ToString(); to LabelLinks.Text = new SPFieldUrlValue(item["Links"].ToString()).Url; Thanks! – Kristian Salov Jan 22 '13 at 9:19
Any idea which control i should use so i can open the link that shows up? I've tried "linkbutton" but it only refreshes the current page! – Kristian Salov Jan 22 '13 at 9:22

You have to use SPFieldUrlValue:

SPFieldUrlValue value = new SPFieldUrlValue(item["Links"].ToString());
string url= value.Url;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.