A quicker way to delete list item versions
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 (foundM开发者_Python百科oreVersionsThanRequired)
{
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?
why not just set the list to only keep 25 versions within SharePoint itself from the web?
精彩评论