2010-06-30 35 views
0

我正在將我們公司的文檔從通用文件服務器遷移到Sharepoint 2010,並想知道是否有任何方法將原始創建日期屬性從文檔中保留下來,以便使用原始創建日期顯示在Sharepoint中,而不是它被添加到Sharepoint的日期。這可能嗎?我們目前在自定義遷移程序中使用Sharepoint的Web服務,將所有文檔從文件服務器添加到Sharepoint,同時在此過程中添加一些元數據值。您是否可以修改Sharepoint 2010文檔上的Date Created屬性?

回答

3

這是不可能使用標準的Web服務,但你可以用這樣的方法寫自己的WS:

[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 
    } 
} 
+0

非常好,謝謝我會試試看。 – 2010-06-30 18:50:59

+0

我使用Sharepoint DLL,所以它結束了一點點不同,但這基本上是我必須做的,謝謝! – 2010-07-07 17:02:56

0

如果它是2010年發佈網站,那麼你可以使用網站菜單下的管理內容鏈接複製或移動文件,它將保留文件系統屬性,包括「創建」,「創建者」,「修改者」修改爲&。

相關問題