0

I need to copy my files from one document library to another document library which reside on another site and Document library contains number folders and sub folders.. The same structure should be maintained by destination library also. They should copy to same sub folders . This should be copied only when field in first document library having status approved? I have coded it in updated event receiver

Any answers will be greatly appreciated?

  • 5
    So what's the problem? – SHug Oct 21 '11 at 13:13
  • 2
    You'll need to provide some code if you're having issues – Tim Gabrhel Oct 21 '11 at 13:15
  • 2
    Which version are you using? Is Content Organizer an option? It does this for you without the need for custom code. – Mike Oryszak Oct 21 '11 at 13:31
1

You have done the right thing for coding in Updated Event Receiver. Since the files must be copied from one document library to another on Status field being updated as approved (i.e. list item "Status" is approved), your code must be in ItemUpdated event receiver.

Code:

if(properties.AfterProperties["Status"] == "Approved") { // your code to copy from one document library to another. }

OR

SPListItem spitem = properties.ListItem;

if(spitem["Status"] == "Approved") { // your code to copy from one document library to another. }

1

You could try using the SPFile.MoveTo() method:

sourceFile.MoveTo(destinationUrl);

Also, here's a link to the MSDN page of this function if you'd like more information:

SPFile.MoveTo method

  • While this may answer the question, a little more context around your code or additional information relating to the function that you've suggested will help to make your answer more complete. – RJ Cuthbertson Feb 15 '13 at 14:32

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