Reputation: 3549
The AttachmentCollection object does not have any delete method. How can i do it?
Upvotes: 1
Views: 4866
Reputation: 59338
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();
}
Upvotes: 5