locked
powershell to add attachments to an item RRS feed

  • Question

  • I can attach a document to an Item using the code below.  But, how can I reference a document stored in a SharePoint Library?

    Like this:

    AddAttachment $item "c:\test.docx"

    AddAttachment $item "http://sharepointed.com/docs/test.docx"

    --------code------

    $web = Get-SPWeb "http://sharepointed.com/"

    $list = $web.GetList("http://sharepointed.com/Lists/Taco/")

    $item = $list.GetItemById(2)

    AddAttachment $item "c:\test.docx"

    function AddAttachment($item, $filePath)

    {

      $bytes = [System.IO.File]::ReadAllBytes($filePath)

      $item.Attachments.Add([System.IO.Path]::GetFileName($filePath), $bytes)

      $item.Update()

    }


    http://www.sharepointed.com
    Wednesday, December 7, 2011 7:33 PM

Answers

All replies