SharePoint Sharpener

Obsessively Sharpening SharePoint

Programmatically Checking if a SharePoint Element is Published

with 3 comments

Here’s a quick tip for you: How to check if the latest version of an element in a SharePoint list is published.

Once you’ve got hold of an SPListItem, you can check the Versions property (an array containing all the versions of the element).

In this block of code IsPublished becomes True if the latest version is published:

bool IsPublished = TheItem.Versions[0].Level == SPFileLevel.Published ? true : false;

 

That’s it.

Written by Thomas Sondergaard

March 26, 2009 at 6:25 pm

3 Responses

Subscribe to comments with RSS.

  1. Thanks. save me some hours :)

    tzriad

    June 22, 2009 at 9:25 am

  2. if it is a file, you can also use this:

    bool isPublished = (TheItem.File.Level == SPFileLevel.Published);

    Ah Lun

    July 30, 2009 at 11:01 am

  3. Appreciated,helped me alot.

    Basem

    October 7, 2009 at 1:06 pm


Leave a Reply