如何在共享点列表中没有列名的情况下删除版本 [英] How to delete versions without having column name in sharepoint list

查看:89
本文介绍了如何在共享点列表中没有列名的情况下删除版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在版本历史中,我得到了一些重复的版本,但没有更改任何字段......所以对于这些版本,列名将为空.以编程方式,我想删除版本历史记录中未指定列名的版本...请帮忙..

In version history i am getting some duplicate versions with out any field changed....So for those versions the column name will be empty. Programmatically i would like to delete the versions in the version history where no column name specified... Please help..

在图像中,您可以看到空白版本...我需要删除这些版本

In the image you can see the blank versions...I need to remove those versions

推荐答案

下面的代码从列表项中删除版本.您可以重复使用,并添加检查名称为空的条件.

The code below deletes versions from the list item. You can re-use it and add the condition of checking the name as empty.

///

    /// 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;

    }

这篇关于如何在共享点列表中没有列名的情况下删除版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆