Private static void ChangeDate(SPListItem item, DateTime date)
{
    // Open fields for edits.
    item.ParentList.Fields[SPBuiltInFieldId.Modified].ReadOnlyField = false;
    item.ParentList.Fields[SPBuiltInFieldId.Created].ReadOnlyField = false;
    item.ParentList.Fields[SPBuiltInFieldId.DiscussionLastUpdated].ReadOnlyField = false;

    // Edit fields.
    item[SPBuiltInFieldId.Created] = date;
    item[SPBuiltInFieldId.Modified] = date;
    item[SPBuiltInFieldId.DiscussionLastUpdated] = date;

    // Save changes.
    item.UpdateOverwriteVersion();
}
Advertisements