Sharepoint 2013 如何以编程方式在sharepoint 2013中获取网站集的ContentType?
如何以编程方式获取子网站中网站集的内容类型?听起来您正试图从子网站获取网站集中内容类型的列表 您可以通过获取根web的句柄并列出其内容类型来实现这一点:Sharepoint 2013 如何以编程方式在sharepoint 2013中获取网站集的ContentType?,sharepoint-2013,content-type,Sharepoint 2013,Content Type,如何以编程方式获取子网站中网站集的内容类型?听起来您正试图从子网站获取网站集中内容类型的列表 您可以通过获取根web的句柄并列出其内容类型来实现这一点: SPContentTypeCollection contentTypes; SPWeb web = SPContext.Current.Web; if (web.IsRootWeb) { contentTypes = web.ContentTypes; } else { contentTypes = web.Site.Root
SPContentTypeCollection contentTypes;
SPWeb web = SPContext.Current.Web;
if (web.IsRootWeb)
{
contentTypes = web.ContentTypes;
}
else
{
contentTypes = web.Site.RootWeb.ContentTypes;
}
要从子网站引用网站集的内容类型,只需使用以下代码:
var web = SPContext.Current.Web;
var contentTypes = web.AvailableContentTypes;
magic属性是AvailableContentTypes,它还返回站点内容类型:
SPContentTypeCollection contentTypes;
SPWeb web = SPContext.Current.Web;
if (web.IsRootWeb)
{
contentTypes = web.ContentTypes;
}
else
{
contentTypes = web.Site.RootWeb.ContentTypes;
}
要以编程方式将网站内容类型添加到列表中,请选择
由返回的集合中的内容类型
SPWeb对象服务器或Web服务器的AvailableContentTypes属性
对象客户端。然后通过以下方式将内容类型添加到列表的集合中:
访问列表对象的ContentTypes属性并调用
添加集合对象的方法。有关详细信息,请参见如何:
将内容类型添加到SharePoint列表