I'm currently adding the URL except the description is an ugly link. I would like to add the description to the URL in a links list on sharepoint online.

My current code to add a new item from an Azure Worker role is as follows :

        using (ClientContext ctx = new ClientContext(cmdSpoSite))
            ctx.ExecutingWebRequest += new EventHandler<WebRequestEventArgs>(ctx_ExecutingWebRequest);

            if (ctx != null)
                List oList = ... // List data etc

                oListItem["Title"] = System.Guid.NewGuid().ToString();
                oListItem["URL"] = url;
                // Adding the URL here but how do I change the description?



The description as seen from the sharepoint list:

enter image description here


FieldUrlValue _url = new FieldUrlValue();
_url.Url = "http://www.google.com";
_url.Description = "Google";
oListItem["URL"] = _url;
SPFieldUrlValue url = new SPFieldUrlValue();
url.Url = "Your Url here";
url.Description = "Your description here";
oListItem["URL"] = url;

EDIT (for CSOM):

FieldUrlValue url = new FieldUrlValue();
url.Url = "Your Url here";
url.Description = "Your description here";
oListItem["URL"] = url;
| improve this answer | |
  • Cheers, seems like this is in the Microsoft.Sharepoint assembly. Any way I could use SPFieldUrlValue in the sharepoint redistributeable. Microsoft.SharePoint.Client – cillierscharl Apr 6 '12 at 16:35
  • Thanks mate, it wouldnt compile with object does not contain a defintion ... So i just instantiated a new FieldUrlValue as seen in my edit above; thank you kindly for your assistance. – cillierscharl Apr 6 '12 at 18:08
  • Np dude. Glad to help. – RJ Cuthbertson Apr 6 '12 at 18:12

I wasn't able to find a Microsoft.SharePoint.dll for O365 2013. Here is how I did it, cheers:

           ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
            var lib = ctx.Web.Lists.GetByTitle("All Project List");
            li = lib.AddItem(itemCreateInfo);
            li["Title"] = "New Item";
            Microsoft.SharePoint.Client.FieldUrlValue u = new Microsoft.SharePoint.Client.FieldUrlValue();
            u.Url = "http://www.espn.com";
            u.Description = "title";
            li["Project"] = u;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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