如何连接到c#中的sharepointsyntex库并从中读取文件



private static void sharepointConnection(({尝试{Console.WriteLine("尝试连接"(;const字符串rootUrl=";const字符串reqUrl=";const字符串pwd=";const字符串username="";

SecureString securestring = new SecureString();
pwd.ToCharArray().ToList().ForEach(s => securestring.AppendChar(s));

ClientContext context = new ClientContext(reqUrl);
context.Credentials = new SharePointOnlineCredentials(username, securestring);

}

catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

验证后使用以下格式的CSOM代码:

public static List<ListItem> GetAllDocumentsInaLibrary()
{
List<ListItem> items = new List<ListItem>();
string sitrUrl = "https://spotenant.sharepoint.com/sites/yoursite";
using (var ctx = new ClientContext(sitrUrl))
{
//ctx.Credentials = Your Credentials
ctx.Load(ctx.Web, a => a.Lists);
ctx.ExecuteQuery();
List list = ctx.Web.Lists.GetByTitle("Documents");
ListItemCollectionPosition position = null;
// Page Size: 100
int rowLimit = 100;
var camlQuery = new CamlQuery();
camlQuery.ViewXml = @"<View Scope='RecursiveAll'>
<Query>
<OrderBy Override='TRUE'><FieldRef Name='ID'/></OrderBy>
</Query>
<ViewFields>
<FieldRef Name='Title'/><FieldRef Name='Modified' /><FieldRef Name='Editor' />
</ViewFields>
<RowLimit Paged='TRUE'>" + rowLimit + "</RowLimit></View>";
do
{
ListItemCollection listItems = null;
camlQuery.ListItemCollectionPosition = position;
listItems = list.GetItems(camlQuery);
ctx.Load(listItems);
ctx.ExecuteQuery();
position = listItems.ListItemCollectionPosition;
items.AddRange(listItems.ToList());
}
while (position != null);
}           
return items;
}

参考

  1. 使用CSOM从SharePoint文档库获取所有文件
  2. 使用C#CSOM从Sharepoint Online文档库下载所有文件

相关内容

  • 没有找到相关文章

最新更新