首页 > 解决方案 > 远程事件接收器-如何在更新或添加列表项之前获取列表项的附件

问题描述

我想添加限制以在列表项中仅上传一个附件。我实现了附件添加事件,但如果用户删除第二个附件,我无法获得最新的附件计数。

标签: sharepoint-onlineevent-receiver

解决方案


您可以使用下面的 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)

使用 CSOM 从 SharePoint 中的列表项中获取所有附件


推荐阅读