I have to programmatically move (archive) a document from document library of a site collection to a document library of another site collection in SharePoint 2010, when a specific value is set for a column in the doc lib.

Would it be possible to write code for this scenario in an event receiver? Is there any other way?

If anybody has any relevant piece of code or links, please share.

Thanks in advance!

2

There are 2 answers

0
Howard On

You could perhaps do a copy operation, then delete the original file.

Have a look at the following link, which discusses copying a file from one site to another:

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfilecollection.aspx

The example uses one site collection. However, if you convert the source document to a byte array you can always instantiate the target site collection and add the binary data to a document library within that site collection.

Certainly the copy operation should would work within the event receiver. However, I'm not certain what will happen if you try to delete the file within the receiver (there may be concurrency issues). If the delete does not work, consider firing a one-time timer job to delete the file (which would occur in a different process).

0
Kusek On

You can try SPExport Class of SharePoint, as per this Article Copy or Move SharePoint items looks like few of the Operations that we do in SharePoint UI uses this API internally to acheive the task. Also this Approach depends if you are trying to do it one time or its going to be a repeatative process.