从我的组织共享点联机服务器下载文件,该文件具有有效凭证,该凭证显示错误,例如“无法联系网站'https://xxx-my.sharepoint.com/”,或者该网站不支持共享点联机凭证。响应状态代码未经授权。 ........“
我的源代码是使用vs2010,.net4.0,任何CPU编译的
public Stream GetFile()
{
using (ClientContext clientContext = GetContextObject())
{
Web web = clientContext.Web;
clientContext.Load(web, website => website.ServerRelativeUrl);
clientContext.ExecuteQuery(); ---> show error while loading server
Regex regex = new Regex(SiteUrl, RegexOptions.IgnoreCase);
string strSiteRelavtiveURL = regex.Replace(FileUrl, string.Empty);
string strServerRelativeURL = CombineUrl(web.ServerRelativeUrl, strSiteRelavtiveURL);
Microsoft.SharePoint.Client.File oFile = web.GetFileByServerRelativeUrl(strServerRelativeURL);
clientContext.Load(oFile);
ClientResult<Stream> stream = oFile.OpenBinaryStream();
clientContext.ExecuteQuery();
return this.ReadFully(stream.Value);
}
}
private ClientContext GetContextObject()
{
ClientContext context = new ClientContext(SiteUrl);
context.Credentials = new SharePointOnlineCredentials("User@domain.com", Password);
return context;
}
clientContext.ExecuteQuery(); // Line throws error