Solved

SPListItem How to get the last published version?

Posted on 2010-11-15
8
3,339 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
 
LVL 12

Expert Comment

by:jagssidurala
ID: 34138603
0
 

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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 12

Accepted Solution

by:
jagssidurala earned 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Note:  There are two main ways to deploy InfoPath forms:  Server-side and directly through the SharePoint site.  Deploying a server-side InfoPath form means the form is approved by the Administrator, thus allowing greater functionality in the form. …
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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