Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm using two textboxes. One textbox that saves the link to my hyperlink column: http://... and one textbox that saves the description. But i can't get it to work. I've tried

            new SPFieldUrlValue(item["Links"].ToString()).Url = TextBoxAddLink.Text;
            new SPFieldUrlValue(item["Links"].ToString()).Description = TextBoxLinkDesc.Text;
share|improve this question

2 Answers 2

up vote 4 down vote accepted

You are making two SPFieldUrlValue objects, for one you are setting Url and for other you are setting Description... Instead use below code:

  SPFieldUrlValue urlValue = new SPFieldUrlValue();
  urlValue.Url = TextBoxAddLink.Text.Trim();
  urlValue.Description = TextBoxLinkDesc.Text.Trim();

  spListItemObject["UrlField"] = urlValue;

This will make a single SPFieldUrlValue object and set both Url and Description properties for a single object, I hope this helps

share|improve this answer
    
I've tried Nadeems answer and it worked. What does trim do? –  Kristian Salov Jan 23 '13 at 13:13
    
Nothing, both the answers are same! Trim we usually use for strings to remove empty spaces from start and end of the string! –  Arsalan Adam Khatri Jan 23 '13 at 13:15
    
Okay. Thank you! –  Kristian Salov Jan 23 '13 at 13:16
    
Personally I would prefer @Arsalans answer for the prcise reason that he added Trim. It removes unnecessary spaces. (+1) –  Nadeem Yousuf Jan 23 '13 at 13:16

Try this:

SPFieldUrlValue value = new SPFieldUrlValue();
value.Description = TextBoxLinkDesc.Text;
value.Url = TextBoxAddLink.Text;
item["Links"] = value;
share|improve this answer

Your Answer

 
discard

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.