We take pride in your success. We let our positivity drive us, day in and out. Talk to us at Mindfire to know us more.

Software Technology Tips

Using Microsoft Sharepoint APIs we can easily Add, Update and Delete list items programmatically. Provided below is a code snippet in C# .Net demonstrating all the three operations..
using (SPSite oSPsite = new SPSite("http://website url/"))
{
using (SPWeb oSPWeb = oSPsite.OpenWeb())
      {
            oSPWeb.AllowUnsafeUpdates = true;
 
            // Fetch the List
            SPList list = oSPWeb.Lists["MyList"];
                   
            //Add a new item in the List
            SPListItem itemToAdd = list.Items.Add();
            itemToAdd["Title"] = "Test Title";
            itemToAdd["Description"] = "Test Description";
            itemToAdd.Update();
 
            // Get the Item ID
            listItemId = itemToAdd.ID;
 
            // Update the List item by ID
            SPListItem itemToUpdate = list.GetItemById(listItemId);
            itemToUpdate["Description"] = "Changed Description";
            itemToUpdate.Update();
 
            // Delete List item
            SPListItem itemToDelete = list.GetItemById(listItemId);
            itemToDelete.Delete();
 
            oSPWeb.AllowUnsafeUpdates = false;
       }
}


Related Tags:

SharePoint

Author: Saroj Dash

top

Related Pages

  • SharePoint Development Skill
  • SharePoint Application Projects

SharePoint

Let us Connect!

privacy

copyright (c) Mindfire Solutions 2007-2012. Login