SharePoint2010 SharePoint Fundation 服务器端对象模型之 枚举网站和网站集
2012-06-01 10:11
302 查看
基本对象模型任务:http://msdn.microsoft.com/zh-cn/library/ms412748
下面的示例枚举当前网站集中所有网站和列表的标题
代码如下:
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
效果如下:
下面例子,返回某个网站下的所有首层子网站的列表:
代码:
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
下面找出根网站集下首层子网站的url以及下面的列表名字
代码如下:
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
获取所有网站集
代码:
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
下面的示例枚举当前网站集中所有网站和列表的标题
代码如下:
SPSite oSiteCollection = SPContext.Current.Site; //获取当前site对象 SPWebCollection collWebsite = oSiteCollection.AllWebs; //获取站点下的所有 web for (int i = 0; i < collWebsite.Count; i++) { using (SPWeb oWebsite = collWebsite[i]) { SPListCollection collList = oWebsite.Lists; for (int j = 0; j < collList.Count; j++) { Label1.Text += SPEncode.HtmlEncode(collWebsite[i].Title) + " " + SPEncode.HtmlEncode(collList[j].Title) + "<BR>"; } } }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
效果如下:
下面例子,返回某个网站下的所有首层子网站的列表:
代码:
SPSite oSiteCollection = SPContext.Current.Site; SPWeb web = new SPSite(oSiteCollection.Url).OpenWeb(); //获取本网站集的根网站 SPWebCollection collWebsite = web.Webs; //获取根网站下的所有首层网站 foreach (SPWeb item in collWebsite) { Label1.Text += SPEncode.HtmlEncode(item.Title) + "<br>"; item.Close(); //请求完毕后关闭site,释放资源 }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
下面找出根网站集下首层子网站的url以及下面的列表名字
代码如下:
string url = @"http://win-s6to7hc4d0o:12345/default.aspx"; SPWeb web = new SPSite(url).OpenWeb(); //根网站集的根网站 SPWebCollection collWebsite = web.Webs; foreach (SPWeb oweb in collWebsite) { foreach (SPList olist in oweb.Lists) { Label1.Text += oweb.Url + " " + olist.Title + "<br>"; } oweb.Close(); }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
获取所有网站集
代码:
SPWebApplication webApplication = SPContext.Current.Site.WebApplication; SPSiteCollection siteCollections = webApplication.Sites; foreach (SPSite siteCollection in siteCollections) { Label1.Text += siteCollection.Url + "<BR>"; siteCollection.Close(); }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
相关文章推荐
- Windows SharePoint Services对象模型
- SharePoint Foundation 2010 托管客户端对象模型概述(五) --使用 CAML 查询列表
- ReportingService错误:配置参数 SharePointIntegrated 被设置为 True,但无法加载 Share Point 对象模型
- Windows SharePoint Services对象模型
- SharePoint服务器端对象模型 之 访问网站和列表数据(Part 2)
- SharePoint Foundation 2010 托管客户端对象模型概述(七) --更新客户端对象\删除客户对象
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第11章节--为Office和SP解决方式开发集成Apps Office的JavaScript对象模型
- SharePoint Foundation 2010 托管客户端对象模型概述(九) --访问大型列表
- SharePoint服务器端对象模型 之 访问网站和列表数据(Part 3)
- SharePoint服务器端对象模型 之 访问网站和列表数据(Part 4)
- sharepoint survey 对象模型
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第9章节--客户端对象模型和REST APIs概览 托管代码(.NET)
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第9章节--client对象模型和REST APIs概览 托管代码(.NET)
- SharePoint Foundation 2010 托管客户端对象模型概述 --创建 Windows 控制台托管的客户端对象模型应用程序
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第11章节--为Office和SP解决方案开发集成Apps Office的JavaScript对象模型
- ReportingService错误:配置参数 SharePointIntegrated 被设置为 True,但无法加载 Share Point 对象模型
- SharePoint服务器端对象模型 之 访问网站和列表数据(Part 5)
- MOSS推荐之2- Windows SharePoint Services对象模型
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第9章节--client对象模型和REST APIs概览 JavaScript
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第9章节--client对象模型和REST APIs概览 client对象模型(CSOM)基础