Programmatically Get Content Types

Title: You might want to get all the content types on a given site

Code:

static void GetListTypeID()
{
using (SPSite oSite = new SPSite(@"http://localhost/"))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
SPContentTypeCollection ctypecoll = oWeb.ContentTypes;
foreach (SPContentType type in ctypecoll)
{
Console.WriteLine("ID: " + type.Id + " ; Name: " + type.Name);
}
}
}
}

Comments

Sandeep said…
Also its worth mentioning the difference b/w
web.ContentTypes and web.AvailableContentTypes

You might get access denied using the 1st one