Change the Created and Last Modified dates in SharePoint/MOSS 2007

sharepointsharepoint-2007

We are migrating a large directory structure of documentation into SharePoint 2007. In our tests, SharePoint obviously sets the created and modified date to the upload time. Is there anyway to change that to the information from the file?

We are already setting various other metadata in our upload script, but it appears that we can't modify those values.

Best Answer

Here are some more details on using the API to update the created and modified dates on items in SharePoint:

SPSite site = new SPSite("http://sharepointsite/subsite");
SPWeb web = site.OpenWeb();
SPList list = web.Lists["My List"];
web.AllowUnsafeUpdates = true;
foreach (SPListItem item in list.Items)
{
   item["Modified"] = "Set the date";
   item["Created"] = "Set the date";
   item.UpdateOverwriteVersion();
}
Related Topic