【发布时间】:2018-05-26 02:17:06
【问题描述】:
我的问题是关于在线共享点。 在我的项目中,我想下载列表项及其版本。我能够下载当前列表项版本,但无法下载其版本。我提到了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 = "指定的参数超出了有效值的范围。\r\n参数名称:serverRelativeUrl"
【问题讨论】:
-
取决于文件版本 For V1.0 test.sharepoint.com/teams/Mycompany/_vti_history/512/Shared Documents/MY CODE.docx
标签: c# sharepoint sharepoint-online