I need to download the Older-Minor version of a File(.docx/.excl etc) inside the SharePoint folder using REST API. The URL would be: https://BaseURL/sites/SubSite/_api/web/GetFileByServerRelativeUrl('/sites/SubSite/Documents/New Folder/xyz.docx')/versions(1)/$value.
When I try to download the Major Versions the file gets downloaded. The problem is only with minor Version.
The major version example is: https://BaseURL/sites/SubSite/_api/web/GetFileByServerRelativeUrl('/sites/SubSite/Documents/New Folder/xyz.docx')/versions(512)/$value.
The API runs fine when I replace the major numbers with (version IDs) 1024,1536,2048... and so on. The major Versions in this case are (version label) 1.0,2.0,3.0 and so on.
But for the minor version of the file: (version label) 0.1,0.2,0.3 etc I need to pass the version Ids as 1,2,3 which returns the Response:
400: Bad Request.
My Sample code is as below:
Note: It's SharePoint 2013 and not SharePoint Online. So I don't have to pass AccessToken.
string resourceUrl = "https://<BaseURL>/sites/<SubSite>/_api/web/GetFileByServerRelativeUrl('/sites/<SubSite>/Documents/New Folder/xyz.docx')/versions(1)/$value";
//string resourceUrl = string.Format("{0}_api/web/GetFileByServerRelativeUrl('{1}')/versions({2})/$value", APIsource, DestinationPath + "/" + FileName, FileVersion.ID);
var wreq = WebRequest.Create(resourceUrl) as HttpWebRequest;
wreq.Headers.Remove("X-FORMS_BASED_AUTH_ACCEPTED");
wreq.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
//wreq.Headers.Add("Authorization", "Bearer " + AccessToken);
wreq.UseDefaultCredentials = true;
wreq.Method = "GET";
wreq.Accept = "application/json; odata=verbose";
wreq.Timeout = 1000000;
wreq.AllowWriteStreamBuffering = true;
wreq.ContentLength = 0;
string result = string.Empty;
string JsonResult = string.Empty;
try
{
WebResponse wresp = wreq.GetResponse();
Stream fs = wresp.GetResponseStream() as Stream;
using (FileStream localfs = File.OpenWrite(LocalTempFolderPath + FileName))
{
CopyStream(fs, localfs);
}
result = "Download Success";
}
catch (Exception ex)
{
LogError(ex);
result = ex.Message;
}
return result;
}