10

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;

2 Answers 2

15
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;
4
  • Cheers, seems like this is in the Microsoft.Sharepoint assembly. Any way I could use SPFieldUrlValue in the sharepoint redistributeable. Microsoft.SharePoint.Client Apr 6, 2012 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. Apr 6, 2012 at 18:08
  • Np dude. Glad to help. Apr 6, 2012 at 18:12
0

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();

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.