2015-04-15 46 views

回答

0

听起来好像你试图从一个子网站获取网站集中的内容类型列表。

你可以得到一个句柄根网站和上市它做到这一点的内容类型:

SPContentTypeCollection contentTypes; 
SPWeb web = SPContext.Current.Web; 
if (web.IsRootWeb) 
{ 
    contentTypes = web.ContentTypes; 
} 
else 
{ 
    contentTypes = web.Site.RootWeb.ContentTypes; 
} 
0

从网站集从一个子网站引用的内容类型,只需使用下面的代码:

var web = SPContext.Current.Web; 
var contentTypes = web.AvailableContentTypes; 

神奇的属性是 “AvailableContentTypes”,这也返回网站内容类型:

要以编程方式将网站内容类型添加到列表,请从SPWeb对象(服务器)的 AvailableContentTypes属性或Web对象(客户端)的Web 属性返回的集合中选择一个 内容类型。然后通过 将内容类型添加到列表集合中,访问列表对象的ContentTypes属性并调用集合对象的Add方法。有关详细信息,请参阅如何: 将内容类型添加到SharePoint列表。

Site and List Content Types (MSDN)

相关问题