I have written some code to delete minor versions after a specific time. I don't know how it is possible, but it only deletes uneven versions, and not the even ones.
Below part is to find all versions that belongs to a specific major version.
minorVersionList = versions.FindAll(x => x.VersionLabel.StartsWith(startLabel) && !x.VersionLabel.EndsWith(".0"));
SPFileVersionCollection versionCollection = item.File.Versions;
List<SPFileVersion> sortedList = minorVersionList.OrderBy(x => x.ID).ToList();
for (int i = 0; i <= sortedList.Count - 3; i++)
{
Console.WriteLine("Deleting Minor Version");
try
{
versionCollection.DeleteByID(sorted[i].ID);
}
catch (Exception ex)
{
Console.WriteLine(ex.InnerException);
}
}
Say I have the following SPFileVersions:
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8
It deletes always the uneven numbers. The SortedList Generic List is being updated every time a Minor version is deleted.
Can someone help with this?