Forum Discussion
KanchanKumbhar
Oct 14, 2020Copper Contributor
SharePoint Remote Event Receiver - ItemAttachmentAdding not providing proper count value
In SharePoint Online List, our requirement is to restrict the user to upload more than 1 attachment hence ewe implemented an RER.
Now after implementing ItemAttachmentAdding the proper count of the attachments is not coming properly.
Any other alternative to get the attachment count on the fly ?
Thanks in advance.
case SPRemoteEventType.ItemAttachmentAdding:
result = new SPRemoteEventResult();
List list = clientContext.Web.Lists.GetById(properties.ItemEventProperties.ListId);
ListItem listItem = list.GetItemById(properties.ItemEventProperties.ListItemId);
clientContext.Load(listItem);
clientContext.ExecuteQuery();
AttachmentCollection oAttachments = listItem.AttachmentFiles; clientContext.Load(oAttachments);
clientContext.ExecuteQuery();
if (null != oAttachments)
{​​​​
if (oAttachments.Count > 0)
{​​​​
result.ErrorMessage = string.Format("More than one attachment is not allowed");
result.Status = SPRemoteEventServiceStatus.CancelWithError;
}​​​​
}​​​​
else
{​​​​
result.ErrorMessage = string.Format("Something went wrong. Please try again");
result.Status = SPRemoteEventServiceStatus.CancelWithError;
}​​​​
No RepliesBe the first to reply