Microsoft.SharePoint.Client 读取SharePoint 文件

https://blog.darkthread.net/blog/access-sharepoint-doclib-with-dotnet/ 可参考它的方法.代码是通用的(它里面包括了文件夹操作等)

我安装的包如下:

 

 读取文件:

   

var ctx = new ClientContext(url);

// Provide credentials
// (Might be able to skip this if the server is on prem and your
// AD user has permissions to access the library)
var password = new SecureString();
foreach (var c in "Sharepoint密码".ToCharArray())
{
password.AppendChar(c);
}

ctx.Credentials =
new SharePointOnlineCredentials("Sharepoint账号", password);

var t= Microsoft.SharePoint.Client.File.OpenBinaryDirect(ctx, "/这一段路径 ");

MemoryStream ms = new MemoryStream();
t.Stream.CopyTo(ms);

 

--注意这里出来的t里的流是不能直接操作的.这里传的路径 是除了https://xxxx.sharepoint.com/这一段路径  ,要注意前面的/ 不能少. 这个路径可以通过 在线查看  选择在桌面应用打开. 然后再找到下图的位置复制出来(注意 不需要最后的参数)

 

posted @ 2020-11-06 13:55  望着天的蜗牛  阅读(822)  评论(0编辑  收藏  举报