Copy attachments from one List to other in Sharepoint
By Santhosh N
This explains how to copy attachments from one to other List in sharepoint.
Here is the code snippet to copy attachments from one List to another in Sharepoint.
private void CopyAttachmentsToList(SPListItem srcItem, SPListItem tgtItem)
{
try
{
//get source item attachments from the folder
SPFolder srcAttachmentsFolder =
srcItem.Web.Folders["Lists"].SubFolders[srcItem.ParentList.Title].SubFolders["Attachments"].SubFolders[srcItem.ID.ToString()];
//Add items to the target item
foreach (SPFile file in srcAttachmentsFolder.Files)
{
byte[] binFile = file.OpenBinary();
tgtItem.Attachments.AddNow(file.Name, binFile);
}
}
catch
{
//exception message goes here
}
finally
{
srcItem.Web.Dispose();
}
}
Related FAQs
SDPS is a deployment solution for the organizations for deploying the application with ease and with less cost
Copy attachments from one List to other in Sharepoint (1618 Views)