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
Lists Members
Lists Web Service
Content Type IDs
[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. 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
Reference
Lists ClassLists Members
Lists Web Service
Other Resources
Content TypesContent Type IDs
DocumentTemplate not returned
Based on my testing in WSS 3.0, the DocumentTemplate is NOT returned in GetListContentTypes as shown above, like this:
<DocumentTemplate TargetName="Forms/NewContentType/template.doc" />
However, it IS returned in GetListContentType, so you can use that method instead.
M.
<DocumentTemplate TargetName="Forms/NewContentType/template.doc" />
However, it IS returned in GetListContentType, so you can use that method instead.
M.
- 2/21/2011
- sympmarc
What the contentTypeId parameter is for...
On closer inspection of the returned xml, I think I have found out the reason for this parameter:
Only one of the ContentType elements will have a boolean attribute called 'BestMatch', set equal to true.
I think that this will be on the content type that is the closest match to the parameter passed in the contentTypeId.
So not useless, just very poorly documented.
Only one of the ContentType elements will have a boolean attribute called 'BestMatch', set equal to true.
I think that this will be on the content type that is the closest match to the parameter passed in the contentTypeId.
So not useless, just very poorly documented.
- 3/19/2009
- JJBongo
Why the contentTypeId parameter?
I can't figure out why the contentTypeId parameter is in this method.
I thought that it might be that you can get all the content types that inherit from the content type id that you pass into it, however on passing "0x0101" (Document) into the method it has return all my Document content types as well as Folder ("0x012...").
So if it isn't a filter, then what's the point of it?
I thought that it might be that you can get all the content types that inherit from the content type id that you pass into it, however on passing "0x0101" (Document) into the method it has return all my Document content types as well as Folder ("0x012...").
So if it isn't a filter, then what's the point of it?
- 3/19/2009
- JJBongo