Advertisement
Guest User

Untitled

a guest
Jul 31st, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. using (SPSite site = new SPSite(SPContext.Current.Site.Url))
  2. {
  3. using (SPWeb web = site.OpenWeb())
  4. {
  5. SPContentType documentContentType = web.AvailableContentTypes[SPBuiltInContentTypeId.Document];
  6. }
  7. }
  8.  
  9. SPContentTypeId id = new SPContentTypeId(BaseContentTypeId);
  10. IList<SPContentType> ContentTypes = web.ContentTypes.Cast<SPContentType>().Where(c => c.Id.IsChildOf(id)).ToList();
  11.  
  12. using (SPSite site = new SPSite(SPContext.Current.Site.Url))
  13. {
  14. using (SPWeb web = site.OpenWeb())
  15. {
  16. SPContentTypeCollection allContentTypes = web.ContentTypes;
  17. SPContentTypeCollection docContentTypes = null;
  18. foreach (SPContentType objContentType in allContentTypes)
  19. {
  20. if (objContentType.Parent.Name == "Document")
  21. {
  22. docContentTypes.Add(objContentType);
  23. }
  24. }
  25. // docContentTypes contains all content types derived from content type "Document". You can implement additional checks and add this into a drop down list.
  26. }
  27. }
  28.  
  29. using System.Collections.Generic;
  30. using Microsoft.SharePoint;
  31. ...
  32. using (SPSite GetSite = new SPSite("http://site"))
  33. {
  34. using (SPWeb TopWeb = GetSite.OpenWeb())
  35. {
  36. SPContentTypeCollection CurContentTypes = TopWeb.ContentTypes;
  37. List<SPContentType> SelectedTypes = new List<SPContentType>();
  38. foreach (SPContentType SPCT in CurContentTypes)
  39. {
  40. if (SPCT.Group == "MyGroup")
  41. {
  42. SelectedTypes.Add(SPCT);
  43. }
  44. }
  45. }
  46. }
  47.  
  48. using (SPSite siteCollection = new SPSite("put your site url here"))
  49. {
  50.  
  51. using (SPWeb Web = siteCollection.OpenWeb())
  52. {
  53.  
  54. SPContentTypeCollection SPCTCol = Web.ContentTypes;
  55. List<string> CustomTypesList = new List<string>();
  56. foreach (SPContentType ContentType in SPCTCol)
  57. {
  58. if (ContentType.Group == "put your content type group name here")
  59. {
  60. CustomTypesList.Add(Convert.ToString(ContentType.Name));
  61. }
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement