SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to copy a list item from one list to an other along with the file attachments which are associated with it.

I am doing this in a custom workflow. I am trying to make a object of a class which is coming from Listdata.svc and the class is of TasksItem.

TasksItem newtask = new TasksItem()
  Title = workflowProperties.Item.Title,

Above is the code which is working fine when copy only simple field like Title of the task etc but I want to know how can we add attachments into it. So the attachments will also get copied to the destination list.


share|improve this question
up vote 2 down vote accepted

To copy the attachment You can use the following code:

foreach (string filename in item.Attachments)
  var file =  item
               .GetFile(item.Attachments.UrlPrefix + fileName);
  var imageData = file.OpenBinary();
  newItem.Attachments.Add(fileName, imageData);
share|improve this answer
newTask.Attachments.Add(attachmentName, attachmentData); 

where attachmentData is a byte-array. You can easily convert attachments to byte[] and add to items.

Check out( warning: error in code sample):

share|improve this answer
How to get the attached file from "workflowproperties.item", let me know. – RHM Feb 9 '12 at 12:59
I m getting Value cannot be null. Parameter name: args on setsavestream method of datacontext – RHM Feb 9 '12 at 13:17
It should be in workflowproperties.Item.Attachments, no? – tarjeieo Feb 9 '12 at 13:55
yes it is...... – RHM Feb 9 '12 at 15:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.