[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SPListItem How to get the last published version?

Posted on 2010-11-15
8
Medium Priority
?
3,544 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 

Author Comment

by:m_a_n
ID: 34138825
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
ID: 34141256
Any clues? Anybody? This is still open!
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 12

Accepted Solution

by:
jagssidurala earned 2000 total points
ID: 34142172
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
 

Assisted Solution

by:m_a_n
m_a_n earned 0 total points
ID: 34150185
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
ID: 34150227
agssidurala was quite close, just missing a few lines as noted in my comment.

Thanks all.
0
 
LVL 12

Expert Comment

by:jagssidurala
ID: 34151890
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
ID: 34182484
jagssidurala was quite close, just missing a few lines as noted in my comment.

Thanks all.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We had a requirement to extract data from a SharePoint 2010 Customer List into a CSV file and then place the CSV file into a directory on the network so that the file could be consumed by an AS400 system. I will share in Part 1 how to Extract the Da…
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

656 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