Sharepoint Online:附件是否也会在删除 ListItem 时删除?

Sharepoint Online: Are attachments also delete on deleting a ListItem?

如果我调用 ListItem.DeleteObject 方法删除我的项目,ListItem 的附件是否也会被删除?或者附件文件还在我的服务器上吗?我怎样才能检查这个?我使用客户端对象模型!

是的,一旦 ListItem.DeleteObject method is invoked and the query is submitted to the server via ClientContext.ExecuteQuery method.

,与列表项关联的附件就会被删除

以下示例演示如何验证附件是否已被删除:

//First, lets delete list item that contains attachments 
var list = ctx.Web.Lists.GetByTitle(listTitle);
var item = list.GetItemById(itemId);
ctx.Load(list.RootFolder, f => f.ServerRelativeUrl);
item.DeleteObject(); //delete list item operation
ctx.ExecuteQuery();

//Then, let's verify whether associated attachment file(s) have been deleted  
var attachamentRootFolderUrl = string.Format("{0}/Attachments",list.RootFolder.ServerRelativeUrl);
var attachamentFolderUrl = string.Format("{0}/{1}", attachamentRootFolderUrl, itemId);
var folder = ctx.Web.GetFolderByServerRelativeUrl(attachamentRootFolderUrl);
var result = ctx.LoadQuery(folder.Folders.Where( f => f.ServerRelativeUrl == attachamentFolderUrl));
ctx.ExecuteQuery();
if (!result.Any())
{
     Console.WriteLine("Attachaments have been deleted.");
}