Webs.GetContentTypes Method
Returns a collection of content type definitions for all site content types on the specified site.
Namespace: [Webs Web service]
Web service reference: http://Site/_vti_bin/Webs.asmx
Syntax
'Declaration
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/sharepoint/soap/GetContentTypes", RequestNamespace := "https://schemas.microsoft.com/sharepoint/soap/", _
ResponseNamespace := "https://schemas.microsoft.com/sharepoint/soap/", _
Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Function GetContentTypes As XmlNode
'Usage
Dim instance As Webs
Dim returnValue As XmlNode
returnValue = instance.GetContentTypes()
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/sharepoint/soap/GetContentTypes", RequestNamespace = "https://schemas.microsoft.com/sharepoint/soap/",
ResponseNamespace = "https://schemas.microsoft.com/sharepoint/soap/",
Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public XmlNode GetContentTypes()
Return Value
Type: System.Xml.XmlNode
An XML fragment in the following form that can be assigned to a System.Xml.XmlNode object.
<ContentTypes>
<ContentType>
…
</ContentTypes>
Each ContentType Element (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="https://schemas.microsoft.com/sharepoint/soap/">
<ContentType
ID="0x010100C78DE4D7C0C57C43AF878D28256599CA"
Name="NewContentType"
Group="Custom Content Types"
Description="Create a new document."
Version="1"
xmlns="https://schemas.microsoft.com/sharepoint/soap/">
<Folder TargetName="Forms/NewContentType" />
<Fields>
…
<DocumentTemplate TargetName="Forms/NewContentType/template.doc" />
<XmlDocuments>
…
</XmlDocuments>
</ContentType>
<ContentType
…
</ContentType>
</ContentTypes>
Remarks
Each content type definition is the same as would be returned by invoking the SchemaXml method.
Examples
The following example retrieves the content type definitions for the specified site, and saves them as an XML file.
Imports System.Xml
Imports System.Web.Services.Protocols
…
Public Sub GetAllSiteContentTypes()
Dim websService As New Web_Reference_Folder_Name.Webs
websService.Credentials = System.Net.CredentialCache.DefaultCredentials
Try
'Retrieve site content type data from Web service.
Dim myNode As XmlNode = websService.GetContentTypes
'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.InnerXml
XmlDoc.AppendChild(root)
XmlDoc.Save("SiteContentTypes.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