The AttachmentCollection object does not have any delete method. How can i do it?
Asked
Active
Viewed 4,583 times
1 Answers
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