Copy list item attachment to Document library


  • Hello Techies,

    I have a requirement to copy list item attachment to document library either through workflow or event receiver.

    Requirement :

    Custom List "A" and Document Library "B" and some workflows(designer workflows) run on item adding(when a user add attachment) on custom list and in that process when the status gets changed in list "A" the attachment should get copied migrated to Document library.

    Note : user will upload only one attachment to list item and only that attachment should be copied / migrated to document library.

     Please help me and let me know how to go about it.
    Either by  workflow or event receiver.

    • Edited by Sachchin Friday, August 19, 2016 12:37 PM change
    Friday, August 19, 2016 12:29 PM


All replies

  • Hi.

    When you attach a file to a list item, you get an URL like this:

    where "2" is the id of your listitem.

    To get the file name you can use REST call like this...


    Then... You can create a Workflow that perform a rest call using the CopyTo method, passing as parameters the right server relative URL.

    CopyTo method

    Copies the file to the destination URL.





    Type: String
    The absolute URL or server relative URL of the destination file path to copy to.


    Type: Boolean
    true to overwrite a file with the same name in the same location; otherwise false.

    HTTP method




      Request example

      url: "<app web url>/_api/SP.AppContextSite(@target)/web
        /getfilebyserverrelativeurl('/Shared Documents/filename.docx')
        ?@target='<host web url>'",
      method: "POST",
      success: successHandler,
      error: errorHandler


    Please mark my answer if it helped you, I would greatly appreciate it.

    Friday, August 19, 2016 12:42 PM
  • Hello Sir,
    I tried your solution, but in workflow history it shows Bad Request.

    screenshot of the SPD workflow

    Where /sites/developer/testDoc/ is the destination library where i need to migrate the attachments.
    Please let me know where am I going wrong.

    • Edited by Sachchin Sunday, August 21, 2016 9:39 AM
    Sunday, August 21, 2016 9:31 AM
  • Hi Sachchin,

    To copy the list item attachments to document library, I recommend to create event receiver for achieving this goal.

    We can use ItemAttachmentAdded event to trigger after adding an attachment to a list item, then copy the attachment to document library.

    About the ItemAttachmentAdded event:

    About how to get list item attachments:

    Best Regards,


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact

    • Marked as answer by Sachchin Tuesday, August 23, 2016 3:24 PM
    Monday, August 22, 2016 2:46 AM
  • Hi,

    Have you ever find the answer to your issue?

    I'm running into the same problem and couldn't find any good answer yet...

    Please share your findings.

    Thanks in advance.

    Monday, March 20, 2017 8:22 PM