Remote Event Receiver-How to get attachment of list item before updating or adding list item

166 views Asked by At

I want to add restriction to upload only one attachment in list item. I implement attachmentadding event, but if user delete the second attachment, I am not able to get the latest attachment count.

1

There are 1 answers

5
Jerry On

You can check the attachment count using CSOM code below:

List targetList = clientContext.Web.Lists.GetByTitle("List Name");
ListItem oItem = targetList.GetItemById(1);
 
AttachmentCollection oAttachments = oItem.AttachmentFiles;
clientContext.Load(oAttachments);
clientContext.ExecuteQuery();

Console.WriteLine(oAttachments.Count)

Get All Attachments From List Item in SharePoint using CSOM