1

I have tried this code to attach a document in custom list for sharepoint online, but it is not working.

$site = [Microsoft.SharePoint.SPSite]("Your site name") $web = $site.OpenWeb() $list = $web.Lists["Your List name"] $item = $list.GetItemById(Your Id) AddAttachment $item "Your Document Name" function AddAttachment($item, $filePath) { $bytes = [System.IO.File]::ReadAllBytes($filePath) $item.Attachments.Add([System.IO.Path]::GetFileName($filePath),$bytes) $item.Update() } 
7
  • 2
    You have to use PowerShell based on client side object model in order to work on SP Online. Commented Oct 1, 2015 at 11:56
  • yes Nadeem I am doing that but it is not working ,I think there is something missing in the code But I am not able to find. Commented Oct 1, 2015 at 11:58
  • 1
    The code you have written is server side code. Commented Oct 1, 2015 at 11:59
  • oh okay. I will check and will let you know. Can you provide code for the same as I am new to Sharepoint. Thanks Commented Oct 1, 2015 at 12:00
  • check this on how to get started sharepointnadeem.com/2015/03/… Commented Oct 1, 2015 at 12:05

1 Answer 1

0

May be an old post, but it looks like you are calling AddAttachment before defining it. Put the function definition at the top.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.