Programmatically Creating a Content Type and Site Column
3 Comments so far
Leave a comment
August 18, 2007, 3:43 pm
Filed under: MOSS
Filed under: MOSS
In this post I show how you can create a content type programmatically and then create a new site column and add it to your new content type.
using(SPSite site = new SPSite(urlToSite))
{
using(SPWeb web = site.OpenWeb())
{
SPContentType contentType =
new SPContentType(web.AvailableContentTypes["Parent Name"],
web.ContentTypes, “Name”);
// use true below to make required field
web.Fields.Add(“NameOfColumn”, SPFieldType.TypeOfField, true);
SPFieldLink fieldLink = new SPFieldLink(web.Fields["NameOfColumn"]);
contentType.FieldLinks.Add(fieldLink);
contentType.Update();
}
}
3 Comments so far
Leave a comment
Leave a comment
Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
i want to give you huge thanks for this effort
wael mohamed software developer from egypt
Comment by wael October 3, 2007 @ 12:49 pmThis is very useful and rare post.
Comment by Abhishek Agrawal December 27, 2007 @ 8:30 amLoyola says : I absolutely agree with this !
Comment by Loyola May 27, 2008 @ 3:09 pm