Tell me more ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to use sharepoint foundation 2010 as file store for a website. Every document update must go thru an approval cycle and finally gets to a approved status to show up on the website for end users. When a document is updated in sharepoint the status is reset to "Draft" even if the previous version was approved. This is the intended behavior.

File.Versions gives me the list of versions.

How to get the version that was last "Approved"?

share|improve this question

1 Answer

Please use below code and this will give latest approved version.

SPList oList = new SPSite("http://developerBOX1").AllWebs["Web1"].GetList( "http://developerBOX1/Web1/DocLIB");

        SPListItemCollection collListItems = oList.Items;
        SPListItem itemFound;
        if (oList.EnableVersioning) 
        {
            foreach (SPListItem oListItem in collListItems)
            {

                SPListItemVersionCollection allVersions = oListItem.Versions;          
                // Iterate through all versions         
                foreach (SPListItemVersion version in allVersions)
                {
                    if (version.Level == SPFileLevel.Published)
                    {
                        itemFound = version.ListItem;
                        return;
                    }
                } 
            } 
        }
share|improve this answer
Thanks.. trying to find SPListItem in CLOM. is this from Webservices by any chance?? – Bhuvan Apr 3 '12 at 22:08
hi bhuvan the CLOM encapsulates sharepoint webservices and gives you a ease of use API – Sebastien Stettler Apr 4 '12 at 7:42
You can write this code in a web service and use this services in your website. I hope this will help you – Yogi Apr 4 '12 at 12:22
Hi Bhuvan, Will this solution help you in your requirment, Please let me know? – Yogi Apr 4 '12 at 14:05
Thanks Yogi.. My problem is that I cannot find the SPList class in CLOM. List class in CLOM doesn't contain Versions property. Can you guide me on how to use this code on the client side. Thanks – Bhuvan Apr 5 '12 at 14:15
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.