SharePoint Difference Between SPWeb.AvailableContentTypes Vs SPWeb.ContentTypes

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);
}
}
}
}

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s