SPSite:
1>SPSite site1 = new
SPSite(
"http:/ /siteName"
);
2>SPSite site2 = new
SPSite(
"http:/ /siteName"
); //使用绝对URL实例化SPSite对象
3>SPSite site3 = new
SPSite(
new
Guid(
"ba3d975e-d956-43da-955b-52fcb1309313"
)) //使用GUID实例化为SPSite对象
4>SPSite site4 = SPContext.Current.Site;
SPWeb:
1>SPWeb web3 = site3.RootWeb;
2>SPWebCollection allWebs = site3.AllWebs;
3>SPWeb web4 = site3.AllWebs["webname"
];
4>SPWeb web5 = site3.OpenWeb("weburl"
);
由于网站集是操作网站、列表、库的根节点,所以首先要掌握好如何获取网站集SPSite对象的方法,在SharePoint 2010中基本可以分三种方法实例化SPSite对象。这三种方法在不同的场合有不同的获取方法。
获取到SPSite对象之后就可以在其下操作相应的对象了,比如:操作网站的SPWeb对象,操作列表的SPList对象等。
下面是完整的获取网站集对象SPSite的几种方法:
02 |
using System.Collections.Generic; |
06 |
using Microsoft.SharePoint; |
08 |
namespace Example.SharePoint2010.ServerOM |
15 |
public void SPSiteMethod() |
17 |
SPSite site1 = new SPSite( "http:/ /siteName" ); |
18 |
SPWeb web1 = site1.RootWeb; |
22 |
using (SPSite site2 = new SPSite( "http:/ /siteName" )) |
24 |
SPWeb web2 = site2.RootWeb; |
27 |
using (SPSite site3 = new SPSite( new Guid( "ba3d975e-d956-43da-955b-52fcb1309313" ))) |
30 |
SPWeb web3 = site3.RootWeb; |
32 |
SPWebCollection allWebs = site3.AllWebs; |
34 |
SPWeb web4 = site3.AllWebs[ "webname" ]; |
36 |
SPWeb web5 = site3.OpenWeb( "weburl" ); |
39 |
SPSite site4 = SPContext.Current.Site; |
==SPWeb对象的几种方法
|
using (SPSite site = new SPSite( "http:/ /develop" )) |
04 |
SPWeb web1 = site.RootWeb; |
06 |
SPWeb web2 = site.OpenWeb(); |
09 |
SPWeb web3 = site.OpenWeb( "strUrlName" ); |
11 |
SPWeb web4 = site.OpenWeb( new Guid( "410CAFBB-23CA-4427-9A13-024C1CF624F5" )); |
13 |
SPWeb web5 = site.AllWebs[ "项目组网站" ]; |
15 |
SPWeb web6 = site.AllWebs[0]; |
17 |
SPWeb web7 = SPContext.Current.Web; |
23 |
using (SPWeb web8 = site.RootWeb) |
25 |
SPList list = web8.Lists[1]; |