Showing posts with label version. Show all posts
Showing posts with label version. Show all posts

Saturday, August 6, 2011

SPFile.Versions.Count & SPListItem.Versions.Count

There is always a confusion between SPFile.Versions.Count & SPListItem.Versions.Count, as to which one to use and what is its purpose.
  

SPListItem.Versions.Count is always 1 more than SPFile.Versions.Count. The reason is SPFile consider the latest version as the current version and therefore does not include this in its version collection.

Thus, SPListItem.Versions.Count[1]  is equal to SPListItem.SPFile.Versions.Count[0].

if you go to  version history of a document , you will get a count equal to SPListItem.Versions.Count

Thus SPListItem.Versions.Count will give you, an exact version count of a document.


Sharepoint Document library - Access denied while reading draft

In your custom code, you might have written a logic to read all documents from a document library. Sometimes you might get access denied for some files in library.

The reason behind this is the version setting of the document library, especially when you have "major & minor" versioning setting enabled. When you track major and minor versions, the major versions are whole numbers, and the minor versions are decimals. Minor versions are the draft versions, major versions are the published ones.
For example, 0.1 is the first minor version of a file, 1.4 is the fourth minor version of a file that was published once, and 3.0 is the third major version of a published file.


The version is stored by default is a minor version. When you save a file and close it, the version is tracked as a minor version. Minor versions are considered drafts that are still being developed.
You must first publish the file in order for it to become a major version. You can publish the file by using drop-down commands in a library

In your API, if lock a sitecollection and then try to read your draft document, obviously you will get "access denied", meaning, the content DB is in read only mode when the site collection is locked


The reason behind this was that, documents were never published [they were in draft mode only]. So documents have to be published with at least one major version to prevent this error.