.Net Console Application读取Sharepoint Document Library方法

显示列表:

ListItemCollection listItemCollection = GetListItemCollection();
if (listItemCollection != null)
{
    if (listItemCollection.Count > 0)
    {

    }
}

得到列表:得到全部子文件夹及文件

 1 public static ListItemCollection GetListItemCollection()
 2         {
 3             ListItemCollection ListItemCollection = null;
 4 
 5             try
 6             {
 7                 ClientContext clientConext = GetClientContext();
 8                 if (clientConext != null)
 9                 {
10                     CamlQuery camlQuery = new CamlQuery();
11                     camlQuery.ViewXml = "<View><Query></Query></View>";
12                     StringBuilder viewField = new StringBuilder();
13 
14                     var filedArray = SPFieldNameList.Split(',');
15                     if (filedArray.Count() > 0)
16                     {
17                         viewField.Append("<ViewFields>");
18                         foreach (var field in filedArray)
19                         {
20                             viewField.Append("<FieldRef Name='" + field + "'/>");
21                         }
22 
23                         viewField.Append("</ViewFields>");
24                     }
25 
26                     string viewFieldStr = viewField.ToString();
27                     camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Query>" + viewFieldStr + "</View>";
28                     ListItemCollection = clientConext.Site.RootWeb.GetListByTitle(SPListName).GetItems(camlQuery);
29                     clientConext.Load(ListItemCollection);
30                     clientConext.ExecuteQuery();
31                 }
32 
33                 Console.WriteLine("Load Sharepoint List Data Success [" + DateTime.Now + "]");
34             }
35             catch (Exception ex)
36             {
37                 Console.WriteLine("Get List Item Collection Error:" + ex.Message);
38             }
39 
40             return ListItemCollection;
41         }

 得到Client Conext:

 1 public static ClientContext GetClientContext()
 2         {
 3             ClientContext resultClientContext = null;
 4             OfficeDevPnP.Core.AuthenticationManager authManager = new OfficeDevPnP.Core.AuthenticationManager();
 5             try
 6             {
 7                 using (var clientContext = authManager.GetNetworkCredentialAuthenticatedContext(SPSiteUrl, SPUserName, SPPassword, Domain))
 8                 {
 9                     bool listExists = clientContext.Site.RootWeb.ListExists(SPListName);
10                     if (listExists == true)
11                     {
12                         resultClientContext = clientContext;
13                     }
14                     else
15                     {
16                         Console.WriteLine("The list[" + SPListName + "] does not exist");
17                     }
18                 }
19             }
20             catch (Exception ex)
21             {
22                 Console.WriteLine("Get Client Context Error:" + ex.Message);
23             }
24 
25             return resultClientContext;
26         }

其中CAML Scope为:

 

原文出处

   

转载于:https://www.cnblogs.com/61007257Steven/p/10609092.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值