0

I am trying to read list item and the attachments from SharePoint 2010 using CSOM Powershell.

But I keep getting below error message Exception calling "ExecuteQuery" with "0" argument(s): "Field or property "AttachmentFiles" does not exist."

I tested same code for SharePoint Online and It works perfectly there.

Below is the code:

$web = $context.web
$list = $web.Lists.GetByTitle("CR_Temporary")

$item = $list.GetItemById(18)
$context.load($item);
$context.ExecuteQuery()


$AttachmentsColl = $item.AttachmentFiles
$context.Load($AttachmentsColl)
$context.ExecuteQuery()

ForEach($Attachment in $AttachmentsColl)
{
    $AttachmentCreation = New-Object Microsoft.SharePoint.Client.AttachmentCreationInformation               
}

Am I missing something here? Please guide me...

Thanks

3
  • Try using $item.Attachments. Jul 29 '19 at 10:04
  • @GaneshSanap I tried. But I am getting Cannot find an overload for "load" and the argument count: "1". Jul 29 '19 at 10:08
  • Check this and this maybe it helps you. Jul 29 '19 at 10:13
1

I tested the code snippet below for "CR_Temporary" list and Item Id "1":

Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll'

$site = 'http://sp/sites/dev'
$context = New-Object Microsoft.SharePoint.Client.ClientContext($site)
$web = $context.web
$list = $web.Lists.GetByTitle("CR_Temporary")

$item = $list.GetItemById(1)
$context.load($item);
$context.ExecuteQuery()


$AttachmentsColl = $item.AttachmentFiles
$context.Load($AttachmentsColl)
$context.ExecuteQuery()

ForEach($Attachment in $AttachmentsColl)
{
   Write-Host("File Name - " + $Attachment.FileName);       
}

enter image description here

3
  • Are you testing this code for SharePoint 2010 ? For me this code works in SharePoint Online But I am facing issue in SharePoint 2010. Jul 30 '19 at 9:47
  • 1
    Yes, tested in SharePoint Server 2010
    – Jerry
    Jul 30 '19 at 9:49
  • Thanks this was very helpful.
    – Andrew
    Oct 31 '19 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.