public static void createContentTypes()
{
string contentTypename = "My Content Type";
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite osite = newSPSite("http://myserver03:7676/abc"))
{
using (SPWeb oweb = osite.OpenWeb())
{
SPContentType contentType = newSPContentType(oweb.ContentTypes["Document"], oweb.ContentTypes, contentTypename);
oweb.ContentTypes.Add(contentType);
contentType.Group = "Custom Content Types";
contentType.Description = "Custom content type";
Console.WriteLine("Content Type Created");
Console.ReadLine();
}
}
});
}
catch (Exception ex)
{
throw ex;
}
}
Note : If you need to add columns to content types programmatically,please check out my blog.I have a post on how to add columns programmatically.
No comments:
Post a Comment