Sunday, July 31, 2016

Updating the Hyperlink or Picture column value Programmatically in SharePoint.

In this article i am sharing the code for updating the Hyperlink or Picture column. We can use this code for both SharePoint list and document library.

            using (SPSite site = new SPSite(SPContext.Current.Web.Site.ID))
            {

                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["TestList"];
                    SPListItem item = list.GetItemById(47);

                    web.AllowUnsafeUpdates = true;

                    //update the Hyperlink or Picture column.
                    SPFieldUrlValue hyper = new SPFieldUrlValue();
                    hyper.Description = "Sharepoint Documents";
                   hyper.Url = "http://Myportal.com/Lists/TestList/Sharepoint Documents.pdf";
                    item["DocumentUrl"] = hyper;
                    item.Update();

                    list.Update();
                    web.AllowUnsafeUpdates = false;

                }

            }