Webs.CreateContentType Method

Creates a new site content type, with the specified columns and properties, on the site.

Web Service: WebsWeb Reference: http://<Site>/_vti_bin/Webs.asmx

Syntax

<SoapDocumentMethodAttribute("http://schemas.microsoft.com/sharepoint/soap/CreateContentType", RequestNamespace:="http://schemas.microsoft.com/sharepoint/soap/", ResponseNamespace:="http://schemas.microsoft.com/sharepoint/soap/", Use:=SoapBindingUse.Literal, ParameterStyle:=SoapParameterStyle.Wrapped)> _
Public Function CreateContentType ( _
    displayName As String, _
    parentType As String, _
    newFields As XmlNode, _
    contentTypeProperties As XmlNode _
) As String

Dim instance As Webs
Dim displayName As String
Dim parentType As String
Dim newFields As XmlNode
Dim contentTypeProperties As XmlNode
Dim returnValue As String

returnValue = instance.CreateContentType(displayName, parentType, newFields, contentTypeProperties)
[SoapDocumentMethodAttribute("http://schemas.microsoft.com/sharepoint/soap/CreateContentType", RequestNamespace="http://schemas.microsoft.com/sharepoint/soap/", ResponseNamespace="http://schemas.microsoft.com/sharepoint/soap/", Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Wrapped)] 
public string CreateContentType (
    string displayName,
    string parentType,
    XmlNode newFields,
    XmlNode contentTypeProperties
)

Parameters

  • displayName
    A string that represents the display name of the new site content type.
  • parentType
    A string that represents the content type ID of the parent content type on which to base the new site content type.
  • newFields
    A string that represents the collection of columns to include on the new site content type.

    Format the column collection as a FieldRefs Element (ContentType) element, where each FieldRef Element (ContentType) child element represents a reference to an existing column to include on the content type.

  • contentTypeProperties
    A string that represents the properties to specify for the new site content type.

    Format the properties as a ContentType Element (ContentType) element, and include the element attributes for the properties you want to specify.

Return Value

Returns the content type ID of the new site content type.

Example

The following example creates a new site content type, based on the Document default content type, on the specified site. The example also specifies a description for the new site content type. Finally, it displays the content type ID of the new content type.

Imports System.Xml
Imports System.Web.Services.Protocols
…
Public Sub CreateNewSiteContentType()
  Dim websService As New Web_Reference_Folder_Name.Webs
  websService.Credentials = System.Net.CredentialCache.DefaultCredentials

  Dim displayName As String = "myNewContentType"
  Dim parentCTId As String = "0x0101"
  Dim xmlDoc As New XmlDocument
  Dim xmlFields As XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "FieldRefs", "")
  Dim xmlProps As XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "ContentType", "")

  Dim xmlPropsDesc As XmlAttribute = xmlDoc.CreateAttribute("Description")
  xmlPropsDesc.Value = "New content type description"
  xmlProps.Attributes.Append(xmlPropsDesc)

  Try
    Dim contentTypeId As String
    contentTypeId = websService.CreateContentType(displayName, parentCTId, xmlFields, xmlProps)
    MessageBox.Show(contentTypeId)

  Catch ex As SoapException
    MessageBox.Show("Message:" + ControlChars.Lf + ex.Message & _
        ControlChars.Lf & _
      "Detail:" + ControlChars.Lf + ex.Detail.InnerText & _
        ControlChars.Lf & _
      "StackTrace:" & ControlChars.Lf + ex.StackTrace)

  Catch ex As Exception
    MessageBox.Show(ex.Message.ToString)

  End Try

End Sub

See Also

Reference

Webs Class
Webs Members
Webs Web Service

Other Resources

Content Types
Content Type Scope
Content Type IDs
Fields and Field References