简体   繁体   English

使用REST调用无法下载Sharepoint Online中不同版本的文件内容

[英]file contents of different versions in Sharepoint Online not getting downloaded using REST Call

I am trying to download a file with its major and minor versions of the file using REST API in java. 我正在尝试使用Java中的REST API下载文件的主要版本和次要版本。 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. 我只能下载特定文件的最新版本,当我尝试下载文件的其他版本时,出现500 Internal Server Error。

The URL to get the versions of the file returns all the versions of the file correctly. 用于获取文件版本的URL会正确返回文件的所有版本。 When I try to get the content of the different versions I get 500 Internal Server Error. 当我尝试获取不同版本的内容时,出现500 Internal Server Error。

The URL I used to get the different versions of the file is 我用来获取文件的不同版本的URL是

" _api/Web/GetFileByServerRelativeUrl('%s')/Versions ". _api / Web / GetFileByServerRelativeUrl('%s')/ Versions ”。

The URL I used to get the content of the file is 我用来获取文件内容的URL是

" _api/web/GetFileByServerRelativeUrl('%s')/$value ". _api / web / GetFileByServerRelativeUrl('%s')/ $ value ”。

The URL syntax for latest version of the file is 文件最新版本的URL语法为

"https:// tenant_name .sharepoint.com/ folder_name/file_name ". “ https:// tenant_name .sharepoint.com / folder_name / file_name ”。

The URL syntax for versions of the file is 文件版本的URL语法为

"https:// tenant_name .sharepoint.com/_vti_history/ version_id / folder_name/file_name ". “ 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? 文件版本的后一种语法(即URL语法)是否存在问题?

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. 似乎支持在端点/_api/web/GetFileByServerRelativeUrl为文件版本指定url,因为它不包括实际文件的服务器相对url。

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: 与其使用REST端点获取文件内容/_api/web/GetFileByServerRelativeUrl('%s')/$value ,不如考虑使用绝对 URL下载文件,如以下示例所示:

C# example C#示例

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM