tekiegreg
tekiegreg

Reputation: 1707

How to copy attachments from a List into a document library via workflow activity

I currently have a task list, some of them contain file attachments. As part of a new workflow I'm creating in MOSS Designer I need to copy the attachments to files in a document library. What is the best way to do this? Is there an activity already made for this? Thanks!

Upvotes: 0

Views: 2412

Answers (1)

Naren
Naren

Reputation: 288

I know it is an old question but for someone out there..

private void MoveAppraisalSupportDocs(SPListItemCollection sourceDocsList, SPList destinationDocsLib)
        {
            int sourceDocCnt = sourceDocsList.Count;

            if (sourceDocCnt > 0)
            {
                for (int sd = 0; sd < sourceDocCnt; sd++)
                {
                    SPListItem sourceItem = sourceDocsList[sd];
                    byte[] fileBytes = sourceItem.File.OpenBinary();
                    string destUrl = destinationDocsLib.RootFolder.Url + "/" + sourceItem.File.Name;
                    SPFile destFile = destinationDocsLib.RootFolder.Files.Add(destUrl, fileBytes, true /*true means overwrite */);
                }
            }
        }

Upvotes: 2

Related Questions