删除列表项版本的更快方法
我的要求是删除除前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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不直接将列表设置为仅在 SharePoint 本身内保留来自 Web 的 25 个版本?
why not just set the list to only keep 25 versions within SharePoint itself from the web?