0

I can't seem to find any other forms on Microsoft or here on StackExchange about version history exporting for 2016 versions of SharePoint. Anybody have any ideas to get a version history export on SharePoint 2016?

Any ideas would be greatly appreciated.

Thanks! :)

2 Answers 2

0

If you want to use CSOM C# code instead of powershell, you can try below code to get version history of file:

Microsoft.SharePoint.Client.File file = web.GetFileByServerRelativeUrl("/Shared Documents/mydocument.doc");
context.Load(file);
context.ExecuteQuery();

ListItem currentItem = file.ListItemAllFields;
context.Load(currentItem);
context.ExecuteQuery();

FileVersionCollection versions = file.Versions;
context.Load(versions);
context.ExecuteQuery();

if (versions != null)
{
    foreach (FileVersion _version in versions)
    {
        Console.WriteLine(_version.Created);
        Console.WriteLine(_version.CheckInComment);
        Console.WriteLine(_version.CreatedBy);
        Console.WriteLine(_version.VersionLabel);
        Console.WriteLine(_version.IsCurrentVersion);
    }
}
1

I have tried the following PowerShell script that working properly on 2013, but I didn't try it on 2016, but it should be working !!

Meanwhile,If you faced any issue to run this script in SharePoint 2016 , you should have a look to How to Adapt your older SharePoint PowerShell Scripts to Support SharePoint 2016

# ******* Variables Section ******************
#Define these variables
$WebURL="http://sharepoint.crescent.com/sites/Sales/"
$ListName ="Invoice"
$ReportFile = "D:\Invoice_VersionHistory.csv"
# *********************************************

#delete file if exists
If (Test-Path $ReportFile)
 {
 Remove-Item $ReportFile
 }

#Get the Web and List
$Web = Get-SPWeb $WebURL
$List = $web.Lists.TryGetList($ListName)

 #Check if list exists
 if($List -ne $null)
 {
  #Get all list items
  $ItemsColl = $List.Items

  #Write Report Header
  Add-Content -Path $ReportFile -Value "Item ID, Version Lable, Created by, Created at, Title"

  #Loop through each item
  foreach ($item in $ItemsColl)
  {
   #Iterate each version
      foreach($version in $item.Versions)
       {
    #Get the version content
    $VersionData = "$($item.id), $($version.VersionLabel), $($version.CreatedBy.User.DisplayName), $($version.Created), $($version['Title'])"
    #Write to report
    Add-Content -Path $ReportFile -Value $VersionData
   }
  }
 }
Write-Host "Version history has been exported successfully!"

Ref : Export SharePoint List Item Version History to CSV

2
  • is there any solution for SP 2010 as well ?
    – kesava
    Nov 28, 2016 at 21:56
  • this will also work for SharePoint 2010 :) Nov 28, 2016 at 22:13

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.