现在的位置: 首页 > 综合 > 正文

得到站点中所有的Content Type

2012年02月07日 ⁄ 综合 ⁄ 共 785字 ⁄ 字号 评论关闭



SPContentTypeId
id =newSPContentTypeId(BaseContentTypeId);
IList<SPContentType>ContentTypes= web.ContentTypes.Cast<SPContentType>().Where(c => c.Id.IsChildOf(id)).ToList();



using(SPSite site =newSPSite(SPContext.Current.Site.Url))
{
 
using(SPWeb web = site.OpenWeb())
   
{
     
SPContentTypeCollection allContentTypes = web.ContentTypes;
               
SPContentTypeCollection docContentTypes =null;
               
foreach(SPContentType objContentType in allContentTypes)
               
{
                   
if(objContentType.Parent.Name=="Document")
                   
{
                        docContentTypes
.Add(objContentType);
                   
}
               
}
               
// docContentTypes contains all content types derived from content type "Document". You can implement additional checks and add this into a drop down list.
   
}
}
可以通过名字去取:
SPContentType spct = web.AvailableContentTypes["ContentTypeName"];
 

抱歉!评论已关闭.