如何下载列表项版本

时间:2017-12-12 11:47:59

标签: c# sharepoint sharepoint-online

我的问题是关于在线sharepoint。 在我的项目中,我想下载列表项及其版本。我可以下载当前的列表项版本但无法下载其版本。我已经提到了this answer,它展示了如何计算规范和修订路径。但在获取数据时,我收到错误

远程服务器返回错误:(403)Forbidden。

并在响应标头中获取值为"访问被拒绝。在此位置%2c中打开文件之前,您必须首先浏览到该网站并选择自动登录的选项。"

 string url = "https://test.sharepoint.com/teams/Mycompany";
ScureString f_SecurePass = new SecureString();
foreach (char ch in password)
    f_SecurePass.AppendChar(ch);

clientcontext = new ClientContext(url);
var credentials = new SharePointOnlineCredentials(userid, f_SecurePass);                
clientcontext.Credentials = credentials;
Web web = clientcontext.Web;
clientcontext.Load(web, website => website.Lists);
clientcontext.ExecuteQuery();

CamlQuery camlQ = new CamlQuery();                            
camlQ.ViewXml = "<View><Query><Where><Geq><FieldRef Name='ID'/>" +
                    "<Value Type='Number'>0</Value></Geq></Where></Query><RowLimit>100</RowLimit></View>";

var cq = _list.GetItems(camlQ);
clientcontext.Load(cq, items => items.Include(item => item.Id,
                item=>item.EffectiveBasePermissionsForUI,
                item=>item.EffectiveBasePermissions));

clientcontext.ExecuteQuery();

var itm  =  _list.GetItemById(itemid);
clientcontext.Load(itm, r => r.Id, r => r.DisplayName);
clientcontext.ExecuteQuery();


foreach (FileVersion itemVersion in itm.File.Versions)
{
  int size = itemVersion.Size;
  string versionlbl =  itemVersion.VersionLabel;
  string newversion = url + itemVersion.Url;
  System.WebClient client = new System.Net.WebClient();
  client.Credentials = new NetworkCredential(userid, f_SecurePass);
  System.IO.Stream Data = client.OpenRead(newversion);// Throws exception
}

如何下​​载列表项版本?

更新:如果我尝试使用

下载文件版本

File.OpenBinaryDirect(clientcontext,newversion); 它抛出以下错误

Message =&#34;指定的参数超出了有效值的范围。\ r \ n参数名称:serverRelativeUrl&#34;

1 个答案:

答案 0 :(得分:1)