How to change SPListItem Created or Modified date

Another often asked question is a ‘How to change SPListItem Created/Modified date’. Such task occur when you importing documents to the SharePoint  from another source when you want to save authorship and time information.

To update Created and Modified date you can use SPListItem indexer to modify infomation and call Update() to save changes.

To modify CreatedBy and ModifiedBy properties, you can use SPListItem indexer to modify fields with internal names Author and Editor. But you should convert SPUser object into string with following format “{userId};#{userName}”

Example you can find below:

public void ApplyMetadata(SPListItem item, DateTime created, DateTime modified, SPUser createdBy, SPUser modifiedBy)
  item["Created"] = created;
  item["Modified"] = modified;

  item["Author"] = GetStringByUser(createdBy);
  item["Editor"] = GetStringByUser(modifiedBy);


private static string GetStringByUser(SPUser user)
  return user.ID + ";#" + user.Name;