SharePoint Online getting error "Column 'Attachments' does not exist. It may have been deleted by another user" when i try to retrive item properties via CSOMs

Ravi Nalla 126 Reputation points
2023-10-18T03:37:53.12+00:00

I am trying to read/get properties of SP document using csom it was working fine until last week. But now suddenly getting error "Column 'Attachments' does not exist. It may have been deleted by another user". This was working since many years but now throwing error. Any idea whether Microsoft changed any thing recently?

the code flow is below

ListItem itemToManage = null;
Web parentWeb = null;
List parentList = null;

this.Site = this.ClientContext.Site;
parentWeb = this.Site.OpenWebById(webId);
parentList = parentWeb.Lists.GetById(listId);
this.RootWeb = this.Site.RootWeb;

itemToManage = parentList.GetItemById(itemId);

ConditionalScope scope = new ConditionalScope(ClientContext, () => (parentWeb.ServerObjectIsNull.Value != true) 
    && (parentList.ServerObjectIsNull.Value != true) && (itemToManage.ServerObjectIsNull.Value != true));

using (scope.StartScope())
{
    //Get all the associated properties and objects generally needed by most of the management processes
    
    ClientContext.Load<ListItem>(itemToManage, i => i.DisplayName, i => i, i => i.Folder, i => i.Folder.Name, i => i.AttachmentFiles,
    i => i.RoleAssignments.Include(ra => ra, ra => ra.Member, ra => ra.Member.Id, ra => ra.Member.LoginName, ra => ra.RoleDefinitionBindings.Include(rd => rd, rd => rd.BasePermissions, rd => rd.Name, rd => rd.Id)),
        i => i.ParentList, i => i.ParentList.Id, i => i.ParentList.DefaultViewUrl, i=>i.ParentList.DefaultDisplayFormUrl, i => i.ParentList.Views, i => i.ParentList.Fields, i => i.ParentList.RootFolder, i => i.ParentList.RootFolder.ServerRelativeUrl, i => i.ParentList.ContentTypes.Include(c => c, c => c.Fields),
        i => i.ParentList.EventReceivers, i => i.ParentList.EventReceivers.Include(er => er.ReceiverName), i => i.ParentList.Description,
        i => i.ContentType, i => i.ContentType.Fields, i => i.ContentType.Parent, i => i.ContentType.Parent.Id,
        i => i.ParentList.ParentWeb, i => i.ParentList.ParentWeb.Id, i => i.ParentList.ParentWeb.SiteUsers, i => i.ParentList.ParentWeb.Language, i => i.ParentList.ParentWeb.RegionalSettings.TimeZone,
        i => i.ParentList.IsApplicationList, i => i.ParentList.IsCatalog, i => i.ParentList.IsPrivate, i => i.ParentList.IsSiteAssetsLibrary, i => i.ParentList.Hidden, i => i.ParentList.BaseTemplate,
        i => i.ParentList.ParentWeb.SiteGroups.Include(g => g, g => g.Users, g => g.Id, g => g.LoginName, g => g.PrincipalType, g => g.Users.Include(u => u, u => u.LoginName, u => u.IsSiteAdmin, u => u.Id)),
        i => i["FileDirRef"],
        i => i.HasUniqueRoleAssignments);

    this.ClientContext.Load<Web>(this.RootWeb, rs => rs, rs => rs.Title);
    this.ClientContext.Load<Site>(ClientContext.Site, s => s.Id, s => s.Url);
}

this.ExecuteQuery();

if ((null == scope.TestResult) || (!scope.TestResult.Value))
{
    itemToManage = null;
}

return itemToManage;


Any help much appreciated.

Thanks,

Ravi Nalla

Microsoft 365 and Office SharePoint Development
Microsoft 365 and Office SharePoint Server Development
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2023-10-18T07:36:56.86+00:00

    Hi @Ravi Nalla,

    Per my test, I am unable to find the Attachments column in the list setting.

    User's image

    User's image

    As the Attachments column is a special column, you could try to retrieve it by Item.AttachmentFiles

    Here is a nice example, please make a reference

    List targetList = clientContext.Web.Lists.GetByTitle("List Name");
     
    // Option 1: Get Item by ID
    ListItem oItem = targetList.GetItemById(11);
     
    // Option 2: Get Item using CAML Query
    CamlQuery oQuery = new CamlQuery();
    oQuery.ViewXml = @"<View><Query><Where>
    <Eq>
    <FieldRef Name='Title' />
    <Value Type='Text'>New List Item</Value>
    </Eq>
    </Where></Query></View>";
     
    ListItemCollection oItems = targetList.GetItems(oQuery);
    clientContext.Load(oItems);
    clientContext.ExecuteQuery();
     
    oItem = oItems.FirstOrDefault();
    // Option 2: Ends Here(Above line)
     
    AttachmentCollection oAttachments = oItem.AttachmentFiles;
    clientContext.Load(oAttachments);
    clientContext.ExecuteQuery();
     
    foreach (Attachment oAttachment in oAttachments)
    {
    Console.WriteLine("File Name - " + oAttachment.FileName);
    }
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.