views:

157

answers:

1

I'm working on migrating our company's documents from a generic file server to Sharepoint 2010 and was wondering if there was any way to keep the original Created Date property from the documents so it shows up in Sharepoint with the original Creation date rather than the date it was added to Sharepoint. Is this possible? We're currently using Sharepoint's web services in a custom migration program to add all the documents to Sharepoint from the file server, while adding some metadata values along the way.

+2  A: 

Hi Shawn

It's not possible using the Standard WebServices, but you could write your own WS with a method like this:

[WebMethod]
public void FixFileData(string fileUrl, DateTime created, DateTime modified, string author, string editor)
{
  Guid siteId = SPContext.Current.Site.ID;
  Guid webId = SPContext.Current.Web.ID;
  try
  {
    SPSecurity.RunWithElevatedPrivileges(delegate
    {
      using (SPSite site = new SPSite(siteId))
      {
        using (SPWeb web = site.OpenWeb(webId))
        {
          SPFile file = web.GetFile(fileUrl);
          SPListItem fileItem = file.Item;
          fileItem[SPBuiltInFieldId.Created] = SPUtility.CreateISO8601DateTimeFromSystemDateTime(created.ToUniversalTime());
          fileItem[SPBuiltInFieldId.Modified] = SPUtility.CreateISO8601DateTimeFromSystemDateTime(modified.ToUniversalTime());
          try
          {
            fileItem[SPBuiltInFieldId.Author]=web.EnsureUser(author);
          }
          catch (Exception)
          {
          // Your loggin code
          }
          try
          {
            fileItem[SPBuiltInFieldId.Editor] = web.EnsureUser(editor);
          }
          catch (Exception)
          {
          // Your loggin code
          }
          fileItem.UpdateOverwriteVersion();
          if (fileItem.ParentList.EnableMinorVersions)
          {
            file.Publish("SPFileUpload");
          }
          if (fileItem.ModerationInformation != null)
          {
            file.Approve("SPFileUpload");
          }
        }
      }
    });
  }
  catch (Exception)
  {
  // Your loggin code
  }
}
Per Jakobsen
Excellent, thanks I'll give that a try.
Shawn Steward
I was using the Sharepoint DLLs so it ended up a little different, but this is basically what I had to do, thanks!
Shawn Steward