Tags

I got this error when I used SPQuery to get all list items and check the version count.

foreach (SPListItem item in myItems)
{

item.Versions.Count

}

after a while searching, you have to change your code like

SPListItem itemCurr = item.ParentList.GetItemById(item.ID);

 

Below is my code to count all documents including versions

SPDocumentLibrary docLib = (SPDocumentLibrary)oSPWeb.Lists[docLibName];

                        Console.WriteLine("Library Name: " + docLib.Title);

                                              

                        SPQuery query = new SPQuery();

                        query.ViewAttributes = "Scope=\"RecursiveAll\"";

                        SPListItemCollection myItems = list.GetItems(query);

                        Console.WriteLine("total Items: " + myItems.Count);

                        foreach (SPListItem item in myItems)
                        {
                            if (!IsFolder(item))
                            {

                                SPListItem itemCurr = item.ParentList.GetItemById(item.ID);
                                Console.WriteLine("item count value: " + itemCurr.Versions.Count);
                                total = total + itemCurr.Versions.Count;
                            }
                        }
About these ads