日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

SharePoint 2010 各个常用级别对象的获取

發布時間:2025/3/20 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SharePoint 2010 各个常用级别对象的获取 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章主旨:獲取SharePoint 2010 中SPFarm, SPWebApplicationCollection, SPWebApplication, SPSiteCollection, SPSite, SPWebCollection, SPWeb, SPListCollection, SPList級別對象的基本操作。【更在于方便自己在工作中的記憶與學習】?

對SharePoint的基本操作有很多,要熟悉它的API不是一朝一夕就能搞定的事情,這篇文章主要是記錄如何獲取SharePoint中List級別以上對象的獲取。下面是我自己測試的代碼,希望對你有所幫助:

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using Microsoft.SharePoint;
6 using Microsoft.SharePoint.Administration;
7
8 namespace GetCommonLevelObject
9 {
10 class CommonLevelObject
11 {
12 //在運行這部分代碼之前要保證:
13 //1:本機已經成功安裝SharePoint
14 //2:本項目里已經添加了SharePoint的服務(并且命名空間添加:SharePoint和SharePoint.Administration)
15 //3:本項目的(屬性)Platform target一定是 x64 或 any cpu,(若是x86則會得不到SharePoint的對象)同時 Application的Target Framework?== .NET Framework 3.5 16 staticvoid Main(string[] args)
17 {
18 //獲取本地SharePoint的Farm(并且輸出Farm的名字)
19 SPFarm mLocalFarm = SPFarm.Local;
20 string mLocalFarmName = mLocalFarm.DisplayName;
21 Console.WriteLine("The Local SPFarm name is: {0}", mLocalFarmName);
22
23
24 //獲取WebApplicationCollection
25 SPWebApplicationCollection mWebAppCol = SPWebService.ContentService.WebApplications;
26 //遍歷WebApplicationCollection中所有的WebApp
27 foreach (SPWebApplication webapp in mWebAppCol)
28 {
29 Console.WriteLine("The name of SPWebApplication is: {0}", webapp.Name);
30 }
31 //獲取WebApplicationCollection中某個特定的WebApp
32 SPWebApplication mWebApp = mWebAppCol["SharePoint - 12345"]; //下標為WebApp的名字或Guid
33
34
35 //獲取某個WebApp下的SiteCollection
36 SPSiteCollection mSiteCol = mWebApp.Sites;
37 //遍歷SiteCollection中所有的Site(即:手動創建的每一個SiteCollection)
38 foreach (SPSite site in mSiteCol)
39 {
40 Console.WriteLine("The name of SPSite is: {0}", site.Url); //site沒有Name和Title屬性
41 }
42 //獲取SiteCollection中某個特定的Site下標為Site的Server_Relative Url或是在SiteCollection中的序號】
?43 SPSite mSite = mSiteCol["sites/MyTeamSiteCollection1"];
44
45
46 //獲取某個Site下的WebCollection(其中包括該Site的RootWeb)
47 //(注:Web的Name是Url上顯示的名字;Title是頁面顯示的名字。手動創建時都可以填寫)
48 SPWebCollection mWebCol = mSite.AllWebs;
49 foreach (SPWeb web in mWebCol)
50 {
51 Console.WriteLine("The title of web is: {0}", web.Title);
52 Console.WriteLine("The name of web is: {0}", web.Name);
53 }
54
55 //獲得某個Site的RootWeb
56 SPWeb rootWeb = mSite.RootWeb;
57 //獲取某個RootWeb(Web)下的WebCollection(其中不包含該RootWeb(Web))
58 SPWebCollection mAnotherWebCol = rootWeb.Webs;
59 foreach (SPWeb web in mAnotherWebCol)
60 {
61 Console.WriteLine("The title of web is: {0}", web.Title);
62 Console.WriteLine("The name of web is: {0}", web.Name);
63 }
64
65 //獲取WebCollection中某個特定的Web
66 SPWeb mWeb = mWebCol["MyTeamSite1"];
67 //獲取某個Web下的SPListCollection(之后的以此類推)
68 //【注:Site沒有.Lists屬性,但是Web有.Lists屬性】
69 SPListCollection mListCol = mWeb.Lists;
70 foreach (SPList list in mListCol)
71 {
72 Console.WriteLine("The title of the list is: {0}", list.Title); //List沒有Name,但是有Title
73 }
74 SPList mList = mListCol["NewCustomList1"];
75
76 }
77 }
78 }
79

?

關于所有List級別以下(Item,Folder,File等等)對象的獲取以后再詳細介紹。

總結

以上是生活随笔為你收集整理的SharePoint 2010 各个常用级别对象的获取的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。