Export (0) Print
Expand All

Lists.GetListContentTypes Method

Windows SharePoint Services 3
Returns a collection of content type definition schemas for all list content types on the given list.

Web Service: ListsWeb Reference: http://<Site>/_vti_bin/Lists.asmx

[SoapDocumentMethodAttribute("http://schemas.microsoft.com/sharepoint/soap/GetListContentTypes", RequestNamespace="http://schemas.microsoft.com/sharepoint/soap/", ResponseNamespace="http://schemas.microsoft.com/sharepoint/soap/", Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Wrapped)] 
public XmlNode GetListContentTypes (
	string listName,
	string contentTypeId
)

Parameters

listName

A string that represents the name of the list on which the content types are located.

contentTypeId

A string that represents the content type ID of the content type.

Return Value

An XML fragment in the following form that can be assigned to a System.Xml.XmlNode object.
<ContentTypes>
  <ContentType>
  ...
</ContentTypes>
Each ContentType element in the XML fragment represents the schema definition for a site content type. The following example return value is edited for clarity.
<ContentTypes xmlns="http://schemas.microsoft.com/sharepoint/soap/">
  <ContentType 
      ID="0x010100C78DE4D7C0C57C43AF878D28256599CA" 
      Name="NewContentType" 
      Group="Custom Content Types" 
      Description="Create a new document." 
      Version="1" 
      xmlns="http://schemas.microsoft.com/sharepoint/soap/">
    <Folder TargetName="Forms/NewContentType" />
    <Fields>
     ...
    <DocumentTemplate TargetName="Forms/NewContentType/template.doc" />
    <XmlDocuments></XmlDocuments>
  </ContentType>
  <ContentType 
    ...
  </ContentType>
</ContentTypes>

Each content type definition is the same as would be returned by invoking the SchemaXml method.

The following example gets the content type definition schemas for the list content types on the specified list.

Imports System.Xml
Imports System.Web.Services.Protocols
…
Public Sub GetAllListContentTypes()
  Dim listService As New Web_Reference_Folder.Lists
  listService.Credentials = System.Net.CredentialCache.DefaultCredentials

  Dim listName As String = "listName"
  Dim contentTypeId As String = "0x0101"

  'Retrieve site content type data from Web service.
  Try
    Dim myNode As XmlNode = listService.GetListContentTypes(listName, contentTypeId)

    'Create XML document.
    Dim XmlDoc As New XmlDocument
    Dim d As XmlNode
    d = XmlDoc.CreateXmlDeclaration("1.0", "", "yes")
    XmlDoc.AppendChild(d)

    'Move Web service data into XML document and save.
    Dim root As XmlNode = XmlDoc.CreateElement("ContentTypes")
    root.InnerXml = myNode.OuterXml
    XmlDoc.AppendChild(root)
    XmlDoc.Save("ListContentTypes.xml")

  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

Community Additions

ADD
Show:
© 2014 Microsoft