2

I run across an issue since yesterday when i use CSOM (c#) to get the URL and description fields from a Hyperlink field?

My first issue starts when i add a longer link to the hyperlink column. It gives me an error with this message The value of this field may not contain more than 255 characters. Is there a way out to fix this issue ?

I have tried to solve this problem by creating rich text column and saving the url text as a link. But i'm not sure if i can call this column as a URL (as a link) in my asp.net application.

My objective is to save all the links (that can trigger new item button for the selected lists) to specified list (in this case "linkst_to_Create") and to fetch for external application.

           foreach ( Microsoft.SharePoint.Client.ListItem listItem in items)
            {

                //  I got Title succesfully. 

                Label1.Text = "" + listItem["Title"];

              // testhyper is hyperlink column in the list

                HyperLink1.NavigateUrl = listItem["testhyper"].ToString();


            }

1 Answer 1

3

listItem["testhyper"].ToString() means you are casting your hyperlink column into string but you need to cast it into FieldUrlValue before using.

var hyperLink = (FieldUrlValue)listItem["testhyper"];

HyperLink1.NavigateUrl = hyperLink.Url;

There other columns like FieldUserValue, FieldChoice & DateTime, where you have to cast before getting values from these columns.

5
  • Now it works for URL field. As I mentioned on top hyperlink field can't contain more than 255 character. So I saved the link in richtext field as a link. But i got error when i call it as URL.
    – gunu
    Commented Nov 13, 2015 at 11:27
  • what is the type of top hyperlink field? is that a single line text field? Commented Nov 13, 2015 at 11:30
  • it is Multiple lines of text
    – gunu
    Commented Nov 13, 2015 at 11:33
  • Try it using listItem["nameOfTheColumn"].ToString(). It should return your link if you allow plain text only Commented Nov 13, 2015 at 11:39
  • NOw it works as charm !! thank you very much. you saved my day
    – gunu
    Commented Nov 13, 2015 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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