2011-08-22 68 views
-1

在版本歷史記錄中,我得到一些重複版本,但沒有更改任何字段....因此對於這些版本,列名將爲空。編程我想刪除的版本在沒有列名指定... 請幫助版本歷史記錄..如何刪除版本列表中沒有列名的版本

Version History 在圖像,你可以看到空白的版本......我需要刪除這些版本

回答

3

下面的代碼從列表項中刪除版本。您可以重新使用它,並將檢查名稱的條件添加爲空。

///

/// Removes unneeded versions from a sharepoint list item 

    /// </summary> 

    /// <param name="item">The SPListItem that needs some versions removed</param> 

    /// <param name="minVersions">The minimum number of versions to keep</param> 

    /// <param name="savedVersions">A collection of important version labels (or null)</param> 

    /// <returns>The number of versions deleted</returns> 

    internal static int RemoveVersions(SPListItem item, int minVersions, ICollection<string> savedVersions) 

    { 

     // Homework for the reader: validate the input arguments. 

     // if item is null, throw an ArgumentNullException 

     // if minVersions < 0 throw an ArgumentOutOfRangeException 



     int deletedCount = 0; 

     int i = minVersions; // start looking for old versions after skipping minVersions 



     while (i < item.Versions.Count) 

     { 

      SPListItemVersion itemVersion = item.Versions[i]; 

      string versionLabel = itemVersion.VersionLabel; 



      if (!itemVersion.IsCurrentVersion && // Not "current" according to SharePoint (e.g. last-published major version, moderated version) 

       (savedVersions == null || !savedVersions.Contains(versionLabel))) // not one of our "saved" versions 

      { 

       itemVersion.Delete(); 

       ++deletedCount; 

      } 

      else 

      { 

       ++i; 

      } 

     } 



     return deletedCount; 

    }