Attachment is related to the list item, so there is no way to directly determine whether there is an attachment in the list. We can traverse each item in the list and determine whether there is an attachment in the list.
// Get all SharePoint lists
ListCollection targetlListCollection = clientContext.Web.Lists;
clientContext.Load(targetlListCollection);
clientContext.ExecuteQuery();
CamlQuery oQuery = CamlQuery.CreateAllItemsQuery();
// Iterate through each list object
foreach (List list in targetlListCollection)
{
if (list.BaseTemplate==100 || list.BaseTemplate == 103 || list.BaseTemplate == 104 || list.BaseTemplate == 105||list.BaseTemplate == 107 || list.BaseTemplate == 106 || list.BaseTemplate == 170)
{
ListItemCollection oCollection = list.GetItems(oQuery);
clientContext.Load(oCollection);
clientContext.ExecuteQuery();
foreach (ListItem oItem in oCollection)
{
clientContext.Load(oItem.AttachmentFiles);
clientContext.ExecuteQuery();
if (oItem.AttachmentFiles.Count > 0)
{
Console.WriteLine(list.Title);
Console.WriteLine(oItem.AttachmentFiles.Count);
break;
}
}
}
}
Tip: If I miss the list template id that can include an attachment in the code, please add it completely.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.