SP.ContentType Class
Collapse the table of content
Expand the table of content

SP.ContentType Class

SharePoint 2010

Last modified: June 24, 2010

Applies to: SharePoint Foundation 2010

Indicates a change to an SP.ContentType Class object. Represents a Web site or list content type.


The following example creates an input button on an application page that initializes a custom content type, adds it to the collection of content types, and displays the names of the current website’s content types.

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/ecmascript" language="ecmascript">

var contentTypeCollection;

function runCode() {
    var clientContext = new SP.ClientContext.get_current();
    if (clientContext != undefined && clientContext != null) {
        var webSite = clientContext.get_web();

        this.contentTypeCollection = webSite.get_contentTypes();

        // Initialize a new content type.
        var contentInfo = new SP.ContentTypeCreationInformation();
        contentInfo.set_description('My custom content type 2');

        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

function onQuerySucceeded() {
    var contentTypeinfo = '';
    var contentTypeEnumerator = this.contentTypeCollection.getEnumerator();
    while (contentTypeEnumerator.moveNext()) {
        var content = contentTypeEnumerator.get_current();
        contentTypeinfo += 'Content Type Name: ' + content.get_name() + '\n';

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

    <input id="Button1" type="button" value="Run Code" onclick="runCode()" />

© 2016 Microsoft