Tuesday, May 24, 2011

updating sharepoint list programmatically

updating sharepoint list programmatically
Recently I encountered the new requirement which wanted to create "Import SharePoint List"
There were more than 700 rows to be updated on a column value had null.
try
            {
                SPSite site = SPContext.Current.Site;
                SPWeb web = site.OpenWeb("http://mosstemp:5000");
                SPList list = web.Lists["Prospects"];

                SPQuery query = new SPQuery();
                query.Query = "";
                SPListItemCollection items = list.GetItems(query);

                foreach (SPListItem item in items)
                {

                    item["Status"] = "Not Called";
                    item.Update();

                }
               
                control = new LiteralControl();
                control.Text = "Updated";
            }
            catch (Exception ex)
            {
                control.Text = ex.InnerException.Message.ToString();
            }
You can't update the "look up" column in the sharepoint list.