Hi Everyone,

I want to write a script that updates the items in a sharepoint list. I would like to use the sharepoint object model to accomplish this. How can I clear all the items in a list, then insert list items from a database query


Re: SharePoint - Development and Programming Updating a Sharepoint list


You can try something along these lines...

Code Snippet

SPSite mySite = new SPSite("http://yourURL");

SPWeb myWeb = mySite.AllWebs["NameOfYourWeb"];

SPList myList = myWeb.Lists["ListName"];

while (myList.ItemCount > 0)



myList = myWeb.Lists["ListName"];


DataTable dt = new DataTable(); //Your Data source here instead

foreach (DataRow dr in dt.Rows)


SPListItem newItem = myList.Items.Add();

newItem["Title"] = dr["Column"];

newItem["OtherColumnName"] = dr["MoreColumns"];