0

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?

1 Answer 1

0

After some communication with an old colleague, I found out that when one of the collections is being updated, the other gets updated to... It is default behaviour of System.Collections like ReadOnlyCollection<>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.