0

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.

1 Answer 1

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>");
            }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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