问题描述
我想添加限制,以仅在列表项中上传一个附件。我实现了attachmentadding事件,但是如果用户删除第二个附件,则无法获得最新的附件计数。
解决方法
您可以使用以下CSOM代码检查附件计数:
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)