0

I am trying to copy all files from a doc lib to another doc lib in another web application, that can be across environments for example DL in SP2010 to DL in SP2013. So I am limited to use Client Object Model to copy files. I am successfully able to copy files but in my requirement , I need to copy all versions as well. Unfortunately I realize, FileVersion object in CSOM, does not have a OpenBinary() method (in server OM, you can use SPFileVersion.OpenBinary())

Does anyone have any idea on how this can be achieved or any work around.

Ondrej Tucny
  • 27,626
  • 6
  • 70
  • 90
sid
  • 43
  • 1
  • 1
  • 6

2 Answers2

0

CSOM does not support downloading historical versions of documents. But you can download them through special _vti_history folder. Here is explained how to do that.

Jan Vanek
  • 889
  • 1
  • 6
  • 8
0

This works for me with SharePoint 2013 with Claims - the user agent header was the key for me.

        private System.Net.WebClient SPWebClient() {

            if (_SPWebClient != null) return _SPWebClient;

            _SPWebClient = new WebClient {

                Credentials = new NetworkCredential(_sharePointUser, _sharePointPassword, _sharePointDomain)

            };

            // for claims based auth
            _SPWebClient.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");

            _SPWebClient.Headers["User-Agent"] = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MDDC)";

            return _SPWebClient;

        }

        foreach (var version in versions) {

            var versionStream = this.SharePointWebClient.OpenRead($"{this.SharePointUrl}/{version.Url}");

            // do something useful

        }
EthR
  • 1,924
  • 1
  • 12
  • 13