2

Can anyone help me to get version history of each file in document set. I have tried as below. here im able to get file name in doc set.

                  SPSite site = SPContext.Current.Site;
                  SPWeb web = site.OpenWeb();

                  string ver = web.Url + "/" + sharedDocs;


                  //Get the selected document
                  SPListItem listItem = SPContext.Current.Web.Lists["Contract Documents"].GetItemById(99);
       if (listItem.FileSystemObjectType == SPFileSystemObjectType.Folder)
        {
          //Get the folder 
          SPFolder myFolder = listItem.Folder;

          //Make sure the folder has items
          if (myFolder.ItemCount > 0)
          {
            //For each item get the document name
            foreach (SPFile item in myFolder.Files)
            { 
              string name = item.Name;
              foreach (SPListItem vh in myFolder.Files)
              {
                 SPListItemVersionCollection coll = vh.Versions;
                 foreach (SPListItemVersion version in coll)
                 {
                     var VersionLabel =version.VersionLabel;


                 }
              }
            }

i'm using sharepoint server 2013.

Please suggest me how to retrieve version history from document set. Thanks in advance.

0

I have done something like this.. Its works fine . But still i didn't get current version of the file. Means I have a file with versions 1.0, 1.1. but it showing count=1 and showing previous one. 1.0

 SPSite site = SPContext.Current.Site;
      SPWeb web = site.OpenWeb();

    //Get the selected document
    SPListItem listItem = SPContext.Current.Web.Lists["Contract Documents"].GetItemById(99);

    if (listItem.FileSystemObjectType == SPFileSystemObjectType.Folder)
    {
      //Get the folder 
      SPFolder myFolder = listItem.Folder;

      //Make sure the folder has items
      if (myFolder.ItemCount > 0)
      {
        //For each item get the document name
        foreach (SPFile item in myFolder.Files)
        { 
          string name = item.Name;
          SPFileVersionCollection filecollection = item.Versions;
          if (filecollection.Count > 0)
             {
               foreach (SPFileVersion v in filecollection)
               {
                  var VersionLabel =v.VersionLabel;
               }

          }
        }

} }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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