删除列表项版本的更快方法

发布于 2024-12-04 19:54:31 字数 1306 浏览 1 评论 0原文

我的要求是删除除前25个之外的所有SPListItem版本...所以我必须从26或索引25开始删除。库中的SPListItem之一有这么多版本...可能超过100k,以至于网络界面无法显示所有版本。数据库的大小接近900GB。

我编写了这段代码,但我认为问题出在 item.Versions 属性上。它尝试加载内存中的所有版本

foreach (SPListItem item in library.Items)
{  
  foundMoreVersionsThanRequired = false;
  int tempVersionToKepp = howManyVersionsToKeep + 1;

  for (int i = 0; i <= tempVersionToKepp; i++)
  {
    SPListItemVersion objVersion = null;

    try
    {
       objVersion = item.Versions[i];
       if (objVersion != null && i == tempVersionToKepp)
       {
         foundMoreVersionsThanRequired = true;
         break;
       }
     }
     catch
     {
       foundMoreVersionsThanRequired = false;
       break;
     }
   }
   if (foundMoreVersionsThanRequired)
   {
     int tempIndex = howManyVersionsToKeep + 1;                     
     SPListItemVersion objVersion = null;
     do
     {
       try
       {
         objVersion = item.Versions[tempIndex];
         if (objVersion != null)
         {
           objVersion.Delete();
         }
         else
           break;
       }
       catch
       {
         break;
       }
     } while (true);
   }
   count++;
 }

我确信问题出在“item.Versions”属性上。似乎当您调用 item.Versions 时,它会加载内存中的所有对象,这会导致很多问题。

有什么方法可以直接删除 SPListItem 版本吗?

My requirement is to delete all the SPListItem versions except the first 25... so I have to start deleting from 26 or index 25. One of the SPListItem in a library has so many versions... may be more than 100k that the web interface is not able to show all the versions. The size of the database is almost 900GB.

I wrote this code but I think the issue is with the item.Versions property. It tries to load all the versions in memory

foreach (SPListItem item in library.Items)
{  
  foundMoreVersionsThanRequired = false;
  int tempVersionToKepp = howManyVersionsToKeep + 1;

  for (int i = 0; i <= tempVersionToKepp; i++)
  {
    SPListItemVersion objVersion = null;

    try
    {
       objVersion = item.Versions[i];
       if (objVersion != null && i == tempVersionToKepp)
       {
         foundMoreVersionsThanRequired = true;
         break;
       }
     }
     catch
     {
       foundMoreVersionsThanRequired = false;
       break;
     }
   }
   if (foundMoreVersionsThanRequired)
   {
     int tempIndex = howManyVersionsToKeep + 1;                     
     SPListItemVersion objVersion = null;
     do
     {
       try
       {
         objVersion = item.Versions[tempIndex];
         if (objVersion != null)
         {
           objVersion.Delete();
         }
         else
           break;
       }
       catch
       {
         break;
       }
     } while (true);
   }
   count++;
 }

I am positive that the issue is with "item.Versions" property. It seems that when you call item.Versions it loads all the objects in the memory and that is causing a lot of issues.

Any way to delete an SPListItem version directly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请帮我爱他 2024-12-11 19:54:31

为什么不直接将列表设置为仅在 SharePoint 本身内保留来自 Web 的 25 个版本?

why not just set the list to only keep 25 versions within SharePoint itself from the web?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文