程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#從Sharepoint上獲取List數據

C#從Sharepoint上獲取List數據

編輯:C#入門知識

C#從Sharepoint上獲取List數據


C#從Sharepoint上獲取List數據:

添加引用:

using Microsoft.SharePoint.Client;
using System.Data;

源碼:

 public static void getDataFromSPList(string siteURL, string listName)
        {
            ClientContext clientContext = new ClientContext(siteURL);
            Web web = clientContext.Web;
            ListCollection collList = web.Lists;

            clientContext.Load(collList);
            clientContext.ExecuteQuery();   //Sharepoint的遠程交互只有在ExecuteQuery之後才被執行的。

            foreach (Microsoft.SharePoint.Client.List list in collList)
            {
                Console.WriteLine("Title:{0}",list.Title);
            }

            //CamlQuery
            CamlQuery camlQuery = new CamlQuery();
            camlQuery.ViewXml = "";

            Microsoft.SharePoint.Client.List planlist = collList.GetByTitle(listName);
            ListItemCollection collListItem = planlist.GetItems(camlQuery);
            clientContext.Load(collListItem,
                items=>items.Include(
                    item=>item.Id,
                    item=>item.DisplayName,
                    item=>item.HasUniqueRoleAssignments)
                );
            clientContext.ExecuteQuery();

            foreach (ListItem olistItem in collListItem)
            {
                Console.WriteLine("ID: {0} \nDisplay name: {1} \nUnique role assignments: {2}",
                    olistItem.Id, olistItem.DisplayName, olistItem.HasUniqueRoleAssignments);
            }
            
            
            clientContext.Load(planlist);
            clientContext.ExecuteQuery();
            Console.WriteLine(planlist.Title.ToString());
            Console.WriteLine(planlist.ItemCount.ToString());
            Console.ReadKey();
        }


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved