Solved

SPListItem How to get the last published version?

Posted on 2010-11-15
8
3,229 Views
Last Modified: 2012-05-10
Hi there,

I will appreciate if somebody can please post the code to find only the last published version of SPListItem.

Thanks.
0
Comment
Question by:m_a_n
  • 5
  • 3
8 Comments
 
LVL 12

Expert Comment

by:jagssidurala
Comment Utility
0
 

Author Comment

by:m_a_n
Comment Utility
This gets the published SPListItem (omitting any entries which do not have a published version).

What I need is "Get the last published version in an SPListItem, even if the latest version is not published".

Thanks for the effort buddy!
0
 

Author Comment

by:m_a_n
Comment Utility
Any clues? Anybody? This is still open!
0
 
LVL 12

Accepted Solution

by:
jagssidurala earned 500 total points
Comment Utility
For Example:
---------------
The list like this

1 --Published
2 -- UP
3 --UP
4 -- P
5-- UP
6 -- Up

Sample code:
--------------------
SPList list = web.Lists[listname];

SPListItem LastPublishedItem = new SPListItem();

foreach (SPListItem item in list.Items)
                {
        if(item.HasPublishedVersion)
            {
              LastPublishedItem = item;      
            }
      }

after excecution of above code the "LastPublishedItem" contains last published version of the above list,
in this case the 4 is the final output.


Refer this link for various properties and methods for SPListItem.

http://msdn.microsoft.com/en-us/library/ms466906.aspx

http://blogs.msdn.com/b/yvan_duhamel/archive/2009/05/27/cannot-get-latest-splistitem-attributes-such-as-forwardlinks-in-a-page-that-was-propagated-using-variations.aspx
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Assisted Solution

by:m_a_n
m_a_n earned 0 total points
Comment Utility
This is what worked for me.

foreach (SPListItemVersion _liv in _li.Versions)
{
 if (_liv.Level == SPFileLevel.Published)
 {
  //Do something
  break;
 }
}
0
 

Author Comment

by:m_a_n
Comment Utility
agssidurala was quite close, just missing a few lines as noted in my comment.

Thanks all.
0
 
LVL 12

Expert Comment

by:jagssidurala
Comment Utility
Thank you for accepting my sol.

Can u also post ur entire code so that i will know whole functionality....
0
 

Author Closing Comment

by:m_a_n
Comment Utility
jagssidurala was quite close, just missing a few lines as noted in my comment.

Thanks all.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

If you create your solutions on SharePoint sooner or later you will come upon a request to set  permissions of the item depending on some of the item's meta-data - the author, people assigned as approvers, divisions, categories etc. The most natu…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now