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/

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

Post a Comment

Popular posts from this blog

SharePoint 2016 and 2019 Ports

Clear fields based on drop-down values in PowerApps

Hide a SharePoint list field based on user group using JQuery Webservice in 2010