Download Document Version History from SharePoint in SSIS

27 June 2022
KingswaySoft Team

SharePoint Document Library supports version histories so that you can store and track different versions of each document file within the library as changes are made to the file. Such version control infrastructure provides many unique benefits. For instance, if something went wrong with one of the files because of a recent accidental/unintended change, you can easily restore to a prior version as needed. In your ETL development, you might often run into the requirements that you need to extract all previous versions of a file. In this blog post, we will show how you could achieve so using our SharePoint Source component to download document library file versions and save them to the local file system using the Premium File System Destination component (offered in SSIS Productivity Pack) in SSIS.

To retrieve the version histories of a document library in SharePoint, you need to enable the “Download Version History” option in the SharePoint Source component, where you can also specify the maximum number of versions to retrieve for each document. In our example, we are retrieving all versions by setting up the property to 0.

Image 001 - SharePoint Source Component

Once the “Download Version History” option has been enabled, a secondary output will be added to the Source Component called Version History (Document Library). Within the new output, you will be able to find all columns related to SharePoint document versions.

Image 002 - SharePoint Source Version History Output

As a general best practice, you should only select those columns/fields that are needed for the downstream pipeline components. As shown in the screenshot above, only “File Content”, “Url” and “Version Number” fields are selected in the Version History output.

Once the SharePoint Source component has been configured, we use a Premium Derived Column component before writing the version histories files to the local system, which uses the following expression to generate the FileName and specify the target parent folder path.

The SharePoint document name can be extracted from the “Url” output column using a Derived Column expression like below:

GetTokenAtPosition( [Url], "/", GetTokenCount( [Url],"/" ))

Given a URL value like “https://{sites}.sharepoint.com/sites/TestSite/DocumentLibrary/Test File.txt”, the output of the above expression is “Test File.txt”, which is the original SharePoint document name.

In order to properly name each downloaded version, we utilize the following expression so that we create a unique name for each file version:

GetTokenAtPosition( GetTokenAtPosition( [Url], "/", GetTokenCount( [Url],"/" )), ".",1 )+"_"+[Version]+"."+GetTokenAtPosition( GetTokenAtPosition( [Url], "/",  GetTokenCount( [Url],"/" )), ".",2 )
For instance, if a file name is “Test File.txt”, the versioned file names will be “Test File_1.0.txt”, “Test File_2.0.txt”, and so on.

Image 003 - Premium Derived Column Functions

A hard-coded target path is also specified in the Premium Derived Column in our example.

Lastly, we write the document library file versions to the local file system using the Premium File System Destination component. The overall data flow design of the package is shown in the screenshot below:

Image 004 - Data Flow Design

By using the above design, you now have an SSIS package that can download SharePoint Document Library version histories and save all files along with their historical versions to a local file system. The design can be further expanded or tailored to suit your unique business requirements, for instance, you can save such document version histories to a different cloud storage space like Amazon S3/Azure Blob Storage/OneDrive using our cloud storage destination components.

We hope you find this blog post helpful.

Archive

November 2024 3 October 2024 1 September 2024 1 August 2024 2 July 2024 1 June 2024 1 May 2024 1 April 2024 2 March 2024 2 February 2024 2 January 2024 2 December 2023 1 November 2023 1 October 2023 2 August 2023 1 July 2023 2 June 2023 1 May 2023 2 April 2023 1 March 2023 1 February 2023 1 January 2023 2 December 2022 1 November 2022 2 October 2022 2 September 2022 2 August 2022 2 July 2022 3 June 2022 2 May 2022 2 April 2022 3 March 2022 2 February 2022 1 January 2022 2 December 2021 1 October 2021 1 September 2021 2 August 2021 2 July 2021 2 June 2021 1 May 2021 1 April 2021 2 March 2021 2 February 2021 2 January 2021 2 December 2020 2 November 2020 4 October 2020 1 September 2020 3 August 2020 2 July 2020 1 June 2020 2 May 2020 1 April 2020 1 March 2020 1 February 2020 1 January 2020 1 December 2019 1 November 2019 1 October 2019 1 May 2019 1 February 2019 1 December 2018 2 November 2018 1 October 2018 4 September 2018 1 August 2018 1 July 2018 1 June 2018 3 April 2018 3 March 2018 3 February 2018 3 January 2018 2 December 2017 1 April 2017 1 March 2017 7 December 2016 1 November 2016 2 October 2016 1 September 2016 4 August 2016 1 June 2016 1 May 2016 3 April 2016 1 August 2015 1 April 2015 10 August 2014 1 July 2014 1 June 2014 2 May 2014 2 February 2014 1 January 2014 2 October 2013 1 September 2013 2 August 2013 2 June 2013 5 May 2013 2 March 2013 1 February 2013 1 January 2013 1 December 2012 2 November 2012 2 September 2012 2 July 2012 1 May 2012 3 April 2012 2 March 2012 2 January 2012 1

Tags