[英]Get previous version file in provider hosted app with client object model
How do i get file of one of previous version using client object model. 如何使用客户端对象模型获取上一版本的文件。 With code I am getting Microsft.sharepoint.client.FileVersion object as expected.
通过代码,我得到了预期的Microsft.sharepoint.client.FileVersion对象。
But trying to do Web.GetFileByServerRelativeUrl(FileVersion.Url) fails. 但是尝试执行Web.GetFileByServerRelativeUrl(FileVersion.Url)失败。
In server object model , I am aware, we can use SPFileVersion.OpenBinaryStream() 我知道在服务器对象模型中,我们可以使用SPFileVersion.OpenBinaryStream()
Looking for client object mode solution. 寻找客户端对象模式解决方案。
I get error as "File not found" when I provide relative url. 提供相对网址时,出现“找不到文件”错误。
There is apparently nothing wrong with relative url format as it works for normal get file for any other files except version files. 相对URL格式显然没有什么问题,因为它适用于除版本文件以外的任何其他文件的正常获取文件。
I Solved this by ussing WebClient to download file data. 我通过使用WebClient下载文件数据来解决此问题。 there are no sharepoint client object model methods available for the purpose.
没有用于此目的的共享点客户端对象模型方法。 this works.
这可行。
public static byte[] GetByteArrayFromVersionFile(Web web,string fileVersionUrl)
{
WebClient wc = new WebClient();
wc.UseDefaultCredentials = true;
wc.Headers.Add("user-agent", " Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0");
byte[] content = wc.DownloadData(web.Url + "/" + fileVersionUrl);
return content;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.