We are using SPWeb.AvailableContentTypes and SPWeb.ContentTypes to get content types from SharePoint.
I was facing an issue regarding content types that some content types are not available from code because I was using AvailableContentTypes from sub site and after some research I found difference between SPWeb.AvailableContentTypes and SPWeb.ContentTypes
SPWeb.ContentTypes :
The ContentTypes property returns only the content types that exist on the current Web site, not all content types in the current scope.
SPWeb.AvailableContentTypes:
Use the AvailableContentTypes property to return all content types in the current scope, including those of any parent Web sites.
static void GetContentTypes()
{
using (SPSite oSite = new SPSite(@”http://dell-pc:9999/”))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
//SPContentTypeCollection ctypecoll = oWeb.ContentTypes; // USING CONTENT TYPES
SPContentTypeCollection ctypecoll = oWeb.AvailableContentTypes; // USING AVAILABLE CONTENT TYPES
foreach (SPContentType type in ctypecoll)
{
Console.WriteLine(“ID: ” + type.Id + ” ; Name: ” + type.Name);
}
}
}
}