Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using (SPSite site = new SPSite(SPContext.Current.Site.Url))
- {
- using (SPWeb web = site.OpenWeb())
- {
- SPContentType documentContentType = web.AvailableContentTypes[SPBuiltInContentTypeId.Document];
- }
- }
- SPContentTypeId id = new SPContentTypeId(BaseContentTypeId);
- IList<SPContentType> ContentTypes = web.ContentTypes.Cast<SPContentType>().Where(c => c.Id.IsChildOf(id)).ToList();
- using (SPSite site = new SPSite(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.
- }
- }
- using System.Collections.Generic;
- using Microsoft.SharePoint;
- ...
- using (SPSite GetSite = new SPSite("http://site"))
- {
- using (SPWeb TopWeb = GetSite.OpenWeb())
- {
- SPContentTypeCollection CurContentTypes = TopWeb.ContentTypes;
- List<SPContentType> SelectedTypes = new List<SPContentType>();
- foreach (SPContentType SPCT in CurContentTypes)
- {
- if (SPCT.Group == "MyGroup")
- {
- SelectedTypes.Add(SPCT);
- }
- }
- }
- }
- using (SPSite siteCollection = new SPSite("put your site url here"))
- {
- using (SPWeb Web = siteCollection.OpenWeb())
- {
- SPContentTypeCollection SPCTCol = Web.ContentTypes;
- List<string> CustomTypesList = new List<string>();
- foreach (SPContentType ContentType in SPCTCol)
- {
- if (ContentType.Group == "put your content type group name here")
- {
- CustomTypesList.Add(Convert.ToString(ContentType.Name));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement