Share via


Webs.CreateContentType method

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

Namespace:  WebSvcWebs
Assembly:  STSSOAP (in STSSOAP.dll)

Syntax

'Declaration
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/sharepoint/soap/CreateContentType", RequestNamespace := "https://schemas.microsoft.com/sharepoint/soap/",  _
    ResponseNamespace := "https://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
'Usage
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("https://schemas.microsoft.com/sharepoint/soap/CreateContentType", RequestNamespace = "https://schemas.microsoft.com/sharepoint/soap/", 
    ResponseNamespace = "https://schemas.microsoft.com/sharepoint/soap/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public string CreateContentType(
    string displayName,
    string parentType,
    XmlNode newFields,
    XmlNode contentTypeProperties
)

Parameters

  • displayName
    Type: System.String

    A string that represents the display name of the new site content type.

  • parentType
    Type: System.String

    A string that represents the content type ID of the parent content type on which to base the new site content type.

  • newFields
    Type: System.Xml.XmlNode

    A string that represents the collection of columns to include on the new site content type.

  • contentTypeProperties
    Type: System.Xml.XmlNode

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

Return value

Type: System.String
Returns the content type ID of the new site content type.

Examples

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

WebSvcWebs namespace

Other resources

Content Types

Content Type Scope

Content Type IDs

Fields and Field References