Thursday, October 20, 2011

Adding, Deleting, copying and downloading attachments in SPList using C#

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
           
            // Delete List item
          for (int i = list.Items.Count - 1; i >= 0; i--)
                {
                    list.Items.Delete(i);
                }


            oSPWeb.AllowUnsafeUpdates = false;
       }
}


http://nehasinha.wordpress.com/2008/05/23/programmticallyc-adding-deleting-copying-and-downloading-attachments-in-splist/

2 comments:

  1. I don't see any code related to Attachments thing!

    ReplyDelete
  2. see below link
    http://nehasinha.wordpress.com/2008/05/23/programmticallyc-adding-deleting-copying-and-downloading-attachments-in-splist/

    ReplyDelete