I am trying to download a file with its major and minor versions of the file using REST API in java. I am able to download only the latest version of the particular file and when I try to download the other versions of the file I am getting 500 Internal Server Error.
The URL to get the versions of the file returns all the versions of the file correctly. When I try to get the content of the different versions I get 500 Internal Server Error.
The URL I used to get the different versions of the file is
" _api/Web/GetFileByServerRelativeUrl('%s')/Versions ".
The URL I used to get the content of the file is
" _api/web/GetFileByServerRelativeUrl('%s')/$value ".
The URL syntax for latest version of the file is
"https:// tenant_name .sharepoint.com/ folder_name/file_name ".
The URL syntax for versions of the file is
"https:// tenant_name .sharepoint.com/_vti_history/ version_id / folder_name/file_name ".
Is there any problem with the latter syntax(ie)URL syntax for file versions?
Anyone please help me out.
It seems it is not supported to specify url for a file version in endpoint /_api/web/GetFileByServerRelativeUrl
since it excepts server relative url of actual file.
Since there is nothing wrong with the provided url for a file version you could consider a different approach to download it. Instead of utilizing REST endpoint for a file content /_api/web/GetFileByServerRelativeUrl('%s')/$value
, consider to download a file using absolute url as demonstrated in the example below:
C# example
using (var client = new HttpClient())
{
var targetPath = @"c:\downloads";
var sourceFileUrl = String.Format("{0}/_vti_history/512/Documents/SharePoint User Guide.docx",webUri);
var response = client.GetAsync(sourceFileUrl).Result;
var targetFileName = targetPath + System.IO.Path.GetFileName(sourceFileUrl);
System.IO.File.WriteAllBytes(targetFileName, response.Content.ReadAsByteArrayAsync().Result);
}
网址应为:
https://sharepoint-site.com/sites/Subsite/_vti_history/version_id/Documents/SharePoint User Guide.docx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.