Solved

SPListItem How to get the last published version?

Posted on 2010-11-15
8
3,254 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
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
 
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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. …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 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