1

I have a site with published pages (pages library).
I need to know programmatically which page is published and which one is not: if I see the pages library as admin, I see in the list all pages regardless of their status (published, draft etc.), while users can only see the last published ones.
The problem is that as administrator I have not a quick look of which pages are really published, because in the list I see only the last version (often a draft), but there can be an older published version. To know whether is there a published version or not I need to go into the the Version History.
I could not find in the list a column with the publishing status: how can I detect quickly if there is a published version or not?

0

One way is to loop through the Versions and check the status, something like:

for (int index = (item.Versions.Count - 1); index >= 0; index--)
{
   if (item.Versions[index].Level == SPFileLevel.Published) 
   {
      // Got the last published item
   }
}
2
  • Yes, I was thinking to something similar, but I have realized that it can't distinguish unpublished pages: even unpublished pages can have a major version (with int number). I have seen that the system must store in somewhere else the information about published/unpublished
    – Marpio
    May 6 '14 at 9:48
  • For unpublished pages the SPFileLevel will be Draft/Checkout, check SPFileLevel.. It doesn't look if its a major version or a minor, it checks what is the Publish status of the page.. May 6 '14 at 10:01
-1

You can use this property SPListItem.HasPublishedVersion

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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