Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'd like get the previous versions of files in document Library, passing as parameter the number of version.

else if(getFileObj.versionNumber!=0)
                                            {
                                                bool found = false;

                                                try
                                                {

                                                /


                                                    foreach(SPListItem items in allegatiCollegati)
                                                {
                                                    SPListItemVersionCollection collectionItemsVersions =items.Versions;

                                                    foreach(SPListItemVersion versions in collectionItemsVersions )
                                                    {
                                                        if(versions.VersionId == getFileObj.versionNumber)
                                                        {
                                                            SPListItem Item = items;
                                                            files.Add(new fileList() { file = Item.File.OpenBinary() });
                                                        }
                                                    }
                                                }
                                                found = true; if(fount== false) {throw new exception("II can't find any file with this version!");}
                                                }
                                                catch (Exception ex)
                                                {

                                                    throw new Exception(ex.Message);
                                                }

I tried with this code but it returns me always the last version of the file.

share|improve this question
add comment

1 Answer 1

look here, you must use SPFile not SPListItem:

foreach (SPFile file in folder.Files)..........


if (file.CheckOutType != SPFile.SPCheckOutType.None)
            {
                html.Append(" Estratto da<a href='" + mySiteHostUrl + file.CheckedOutByUser.LoginName + @"' class='author'>" + file.CheckedOutByUser.Name + @"</a>");
            }
            html.Append(@"</div>
        </div>");

            if (file.Versions.Count > 0)
            {
                html.Append("<div class='versions' style='display:none;' id='ver-id-" + file.Item.ID + "'><ul>");

                foreach (SPFileVersion version in file.Versions)
                {
                    html.Append("<li><div class='author'><a target='_blank' href='" + string.Format("{0}/{1}", file.Web.Url, version.Url) + "'>" + version.VersionLabel + "</a> " + version.Created.ToString() + " <a href='" + mySiteHostUrl + version.CreatedBy.LoginName + @"' class='author'>" + version.CreatedBy.Name + "</a></div></li>");
                }

                html.Append("</ul></div>");
            }
share|improve this answer
add 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.