使用 OpenBinaryDirect 方法的 SharePoint 2013 文档库出现远程服务器 401 未授权错误?
SharePoint 2013 Document Library by using OpenBinaryDirect method I got remote server 401 unauthorized error?
当我使用 OpenBinaryDirect 方法从 SharePoint 2013 文档库检索文件时,出现远程服务器 401 未授权错误?你能帮我解决问题吗
使用以下方式提供在线凭证
SharePointOnlineCredentials(username,password) class 在你的代码中
代码:
字符串用户名="xxx";
字符串密码="xx";
SecureString ss=new SecureString();
foreach(密码中的字符c)
ss.AppendChar(c)
clientcontext.credentials = SharePointOnlineCredentials(用户名,ss);
Web web = clientContext.Web;
List list = web.Lists.GetById(new Guid("xxxxxxxxxx"));
var data = new CamlQuery() { ViewXml = "query" };
Microsoft.SharePoint.Client.ListItemCollection items_attachments = list.GetItems(数据);
clientContext.Load(items_attachments);
clientContext.ExecuteQuery();
foreach(items_attachments 中的Microsoft.SharePoint.Client.ListItem 列表项)
{
clientContext.Load(listitem, i => i.File);
clientContext.ExecuteQuery();
var fileRef = listitem.File.ServerRelativeUrl;
文件信息 fileinfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, fileRef);
流 fl = fileinfo.Stream;
byte[] s = ReadFully(fl);
}
public static byte[] ReadFully(流输入)
{
byte[] buffer = new byte[16 * 1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}
当我使用 OpenBinaryDirect 方法从 SharePoint 2013 文档库检索文件时,出现远程服务器 401 未授权错误?你能帮我解决问题吗
使用以下方式提供在线凭证 SharePointOnlineCredentials(username,password) class 在你的代码中
代码:
字符串用户名="xxx";
字符串密码="xx";
SecureString ss=new SecureString();
foreach(密码中的字符c) ss.AppendChar(c)
clientcontext.credentials = SharePointOnlineCredentials(用户名,ss);
Web web = clientContext.Web;
List list = web.Lists.GetById(new Guid("xxxxxxxxxx"));
var data = new CamlQuery() { ViewXml = "query" };
Microsoft.SharePoint.Client.ListItemCollection items_attachments = list.GetItems(数据);
clientContext.Load(items_attachments);
clientContext.ExecuteQuery();
foreach(items_attachments 中的Microsoft.SharePoint.Client.ListItem 列表项) {
clientContext.Load(listitem, i => i.File);
clientContext.ExecuteQuery();
var fileRef = listitem.File.ServerRelativeUrl;
文件信息 fileinfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, fileRef);
流 fl = fileinfo.Stream;
byte[] s = ReadFully(fl);
}
public static byte[] ReadFully(流输入) {
byte[] buffer = new byte[16 * 1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}