The code can be used to copy items from one site to another ,but source and destination sites must be in same server.
If the item was added newly in a Document Library , Item Checked In Event Handler must be used :
public override void ItemCheckedIn(SPItemEventProperties properties)
{
base.ItemCheckedIn(properties);
try
{
SPSite sourceSite = new SPSite("Source Site URL");
SPWeb sourceweb = sourceSite.OpenWeb();
SPList sourcelist = sourceweb.Lists["Source List"];
if (properties.ListTitle == sourcelist.Title)
{
SPListItem sourceitem = properties.ListItem;
string title = sourceitem["Title"].ToString();
string description = sourceitem["ToolName"].ToString()";
SPSite _destSite = new SPSite("Destination Site URL");
SPWeb _destweb = _destSite.OpenWeb();
SPList _destList = _destweb.Lists["DestinationList"];
SPListItem _destitem = _destList.Items.Add();
destweb.AllowUnsafeUpdates = true;
destitem["Title"] = title;
destitem["Description"] = description;
destitem.SystemUpdate();
destList.Update();
destweb.AllowUnsafeUpdates = false;
}
}
catch (Exception ex)
{
properties.ErrorMessage = ex.Message;
}
}
Comments
Post a Comment