Solved

SPListItem How to get the last published version?

Posted on 2010-11-15
8
3,301 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
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.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple Injector with Web Service 4 54
2 questions 10 29
Printing 1 58
jquery + C#.net radiobuttonlist 3 30
Pimping Sharepoint 2007 without Server-Side Code Part 1 One of my biggest frustrations with Sharepoint 2007 in the corporate world is that while good-intentioned managers lock down the more interesting capabilities of Sharepoint programming in…
The vision: A MegaMenu for a SharePoint portal home page The mission: Make it easy to maintain. Allow rich content and sub headers as well as standard links. Factor in frequent changes without involving developers or a lengthy Dev/Test/Prod rel…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
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 …

829 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