0

The AttachmentCollection object does not have any delete method. How can i do it?

Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193
Vikram Babu Nagineni
  • 3,411
  • 6
  • 25
  • 34

1 Answers1

4

AttachmentCollection class does not expose any methods for deleting attachments, but you could utilize Attachment.DeleteObject method to delete an Attachment from a collection.

The following example demonstrates how to delete all attachments in list item:

public static void DeleteAttachmentFiles(ClientContext context, string listTitle,int listItemId)
{
    var list = context.Web.Lists.GetByTitle(listTitle);
    var listItem = list.GetItemById(listItemId);
    context.Load(listItem, li => li.AttachmentFiles);
    context.ExecuteQuery();
    listItem.AttachmentFiles.ToList().ForEach(a => a.DeleteObject()); 
    context.ExecuteQuery();
}
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193