I am creating a event handler that will sync documents between two sites on the same site collection when one is uploaded. This is the item added handler.
public override void ItemAdded(SPItemEventProperties properties)
{
using (DisabledItemEventsScope scope = new DisabledItemEventsScope())
{
try
{
using (SPWeb web = properties.Web)
{
SPListItem doc = properties.ListItem;
String path = (String)doc[path_field];
SPFile file = (SPFile)web.GetFileOrFolderObject(path_field);
using (SPSite destSite = new SPSite(dest_url))
{
using (SPWeb destWeb = destSite.OpenWeb())
{
SPFolder destFolder = destWeb.Folders[dest_fold_url];
destWeb.AllowUnsafeUpdates = true;
destFolder.Files.Add(file.Name, file.OpenBinary(), true);
destFolder.Update();
}
}
}
}
catch (Exception e)
{
properties.ListItem[error_field] = e.Message;
properties.ListItem.Update();
}
}
}
However I keep getting a Exception User-Unhandled : Exception has been thrown by the target of an invocation when I create the new site on the line using (SPSite destSite = new SPSite(dest_url)). I looked at the inner exception and it was this.
InnerException {"Specified argument was out of the range of valid values.\r\nParameter name: Creation of SPSite objects with a different site id or a different user token is not allowed."} System.Exception {System.ArgumentOutOfRangeException}
Any idea why this is happening and how to fix it?