开发者

Can you modify the Date Created property on Sharepoint 2010 documents?

开发者 https://www.devze.com 2023-01-05 11:21 出处:网络
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

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 Sharep开发者_开发技巧oint'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.


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
  }
}


If it's a 2010 Publishing site then you can use the Manage Content link under the Site Menu to copy or move files and it will preserve the file system attributes, including Created, Created By, Modified & Modified By.

0

精彩评论

暂无评论...
验证码 换一张
取 消