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 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?

                oListItem.Update();

                ctx.ExecuteQuery();
            }
        }

The description as seen from the sharepoint list:

enter image description here

Edit

FieldUrlValue _url = new FieldUrlValue();
_url.Url = "http://www.google.com";
_url.Description = "Google";
oListItem["URL"] = _url;
share

2 Answers 2

up vote 6 down vote accepted
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;
share
    
Cheers, seems like this is in the Microsoft.Sharepoint assembly. Any way I could use SPFieldUrlValue in the sharepoint redistributeable. Microsoft.SharePoint.Client –  f0x 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. –  f0x 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;
            li.Update();
            ctx.Load(li);
            ctx.ExecuteQuery();
share

This site is currently not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .