I have implemented an event receiver on a SharePoint 2007 (MOSS) document library, to perform certain validations via the itemUpdating
method and to copy the document to a document library in another site collection (and perhaps even an other farm, if possible?) via the itemUpdated
method. The code looks like this:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(targetWebsiteUrl))
{
using (SPWeb web = site.OpenWeb())
{
var targetLibrary = web.Lists[targetDocLibName];
using (Stream fileStream = file.OpenBinaryStream())
{
SPFile copiedFile = targetLibrary.RootFolder.Files.Add(fileName, fileStream);
}
}
}
});
I am not sure if the above code works across farms, but it certainly copies the file to the destination website and document library. But I am unable to copy over any meta-data associated with the original document. Is there any wahway to copy over the meta-data, or is that a separate step and update?