Jason
Jason

Reputation: 1105

Setting created and modified dates for Sharepoint 2010 list items

I'm working on a Powershell script to migrate data from an existing SQL Server database into Sharepoint 2010 lists. Some of the records in the existing database have created and modified dates which the client would like to carry over into Sharepoint.

My migration script uses the UpdateListItems method on Sharepoint Lists web service to upload batches of CAML to create the new items. I have updated my CAML to set the "Created" column however the value seems to get ignored and is just set to the current date.

Is it possibly to manually set these dates either through the web services or through the ProcessBatchData method on the SPWeb object? I've seen examples online which imply that it can be done for individual items by disabling system update and tweaking versioning settings. However working with individual items is not an option since we have about 800,000 list items to import.

Upvotes: 3

Views: 3114

Answers (1)

Jason
Jason

Reputation: 1105

Solution was to change from using web services to using SPWeb.ProcessBatchData to import my data (thanks Andreas).

The XML passed into this method looks like:

<ows:Batch OnError="Continue">
  <Method ID="1">
    <SetList />
    <SetVar Name="ID">New</SetVar>
    <SetVar Name="Cmd">Save</SetVar>
    <SetVar Name="urn:schemas-microsoft-com:office:office#ColumnName1">Value</SetVar>
    <SetVar Name="urn:schemas-microsoft-com:office:office#Modified">2009-09-03T15:05:00Z</SetVar>
    <SetVar Name="urn:schemas-microsoft-com:office:office#Created">2004-01-15T13:48:00Z</SetVar>
  </Method>
  <Method ID="2">
    ...
  </Method>
  ...
</ows:Batch>

The "SetList" element should contain the Guid for the list to add the data too. In my example XML above this is empty because the XML is pre-generated before importing the data into SharePoint and we can't guarantee that the Sharepoint list Guid on the target server would be the same so we fill this in just before importing.

I also had to ensure that the dates being passed in where in the correct format by passing them into the SPUtility.CreateISO8601DateTimeFromSystemDateTime method.

Upvotes: 1

Related Questions