Dump the Entity Metadata
![]() |
[Applies to: Microsoft Dynamics CRM 4.0]
Find the latest SDK documentation: CRM 2015 SDK
This sample shows how to use the MetadataService Web Service. It creates an XML file that provides a snapshot of attributes for a single entity using the Metadata APIs. You can then open this file with Microsoft Office Excel.
This sample code can be found in the following files in the SDK download:
Server\HowTo\CS\Metadata\HowToMetadata.cs
Server\HowTo\VB\Metadata\HowToMetadata.vb
For more information about the helper methods in the Microsoft.Crm.Sdk.Utility.CrmServiceUtility namespace, see Utility Sample Code.
Example
[C#]
sing System;
using System.Xml.Serialization;
using System.Xml;
using System.IO;
using Microsoft.Crm.Sdk.Utility;
using CrmSdk;
using MetadataServiceSdk;
namespace Microsoft.Crm.Sdk.HowTo
{
/// <summary>
/// This sample shows how to retrieve all the metadata and write it to a file.
/// </summary>
public class HowToMetaData
{
static void Main(string[] args)
{
// TODO: Change the server URL and Organization to match your CRM Server and CRM Organization
HowToMetaData.Run("https://localhost:5555", "CRM_SDK");
}
public static bool Run(string crmServerUrl, string orgName)
{
// Standard MetaData Service Setup
MetadataService service = CrmServiceUtility.GetMetadataService(crmServerUrl, orgName);
#region Setup Data Required for this Sample
bool success = false;
#endregion
try
{
// Retrieve the Metadata
RetrieveAllEntitiesRequest request = new RetrieveAllEntitiesRequest();
request.MetadataItems = MetadataItems.All;
RetrieveAllEntitiesResponse metadata = (RetrieveAllEntitiesResponse)service.Execute(request);
// Create an instance of StreamWriter to write text to a file.
// The using statement also closes the StreamWriter.
using (StreamWriter sw = new StreamWriter("testfile.xml"))
{
// Create Xml Writer.
XmlTextWriter metadataWriter = new XmlTextWriter(sw);
// Start Xml File.
metadataWriter.WriteStartDocument();
// Metadata Xml Node.
metadataWriter.WriteStartElement("Metadata");
AttributeMetadata currentAttribute;// Declared outside of loop
// Iterate through all entities and add their attributes and relationships to the file.
foreach(EntityMetadata currentEntity in metadata.CrmMetadata)
{
// Start Entity Node
metadataWriter.WriteStartElement("Entity");
// Write the Entity's Information.
metadataWriter.WriteElementString("Name", currentEntity.LogicalName);
if (currentEntity.DisplayName.UserLocLabel != null)
{
metadataWriter.WriteElementString("DisplayName", currentEntity.DisplayName.UserLocLabel.Label);
}
else
{
metadataWriter.WriteElementString("DisplayName", "[NONE]");
}
if (currentEntity.DisplayCollectionName.UserLocLabel != null)
{
metadataWriter.WriteElementString("DisplayCollectionName", currentEntity.DisplayCollectionName.UserLocLabel.Label);
}
else
{
metadataWriter.WriteElementString("DisplayCollectionName", "[NONE]");
}
metadataWriter.WriteElementString("IsCustomEntity", currentEntity.IsCustomEntity.ToString());
metadataWriter.WriteElementString("IsCustomizable", currentEntity.IsCustomizable.ToString());
metadataWriter.WriteElementString("ReportViewName", currentEntity.ReportViewName);
metadataWriter.WriteElementString("PrimaryField", currentEntity.PrimaryField);
metadataWriter.WriteElementString("PrimaryKey", currentEntity.PrimaryKey);
#region Attributes
// Write Entity's Attributes.
metadataWriter.WriteStartElement("Attributes");
for (int j = 0; j < currentEntity.Attributes.Length; j++)
{
// Get Current Attribute.
currentAttribute = currentEntity.Attributes[j];
// Start Attribute Node
metadataWriter.WriteStartElement("Attribute");
// Write Attribute's information.
metadataWriter.WriteElementString("Name", currentAttribute.LogicalName);
metadataWriter.WriteElementString("Type", currentAttribute.AttributeType.ToString());
if (currentAttribute.DisplayName.UserLocLabel != null)
{
metadataWriter.WriteElementString("DisplayName", currentAttribute.DisplayName.UserLocLabel.Label);
}
else
{
metadataWriter.WriteElementString("DisplayName", "[NONE]");
}
metadataWriter.WriteElementString("Description", currentAttribute.IsCustomField.ToString());
metadataWriter.WriteElementString("IsCustomField", currentAttribute.IsCustomField.ToString());
metadataWriter.WriteElementString("RequiredLevel", currentAttribute.RequiredLevel.ToString());
metadataWriter.WriteElementString("ValidForCreate", currentAttribute.ValidForCreate.ToString());
metadataWriter.WriteElementString("ValidForRead", currentAttribute.ValidForRead.ToString());
metadataWriter.WriteElementString("ValidForUpdate", currentAttribute.ValidForUpdate.ToString());
// Write the Default Value if it is set.
if (currentAttribute.DefaultValue != null)
{
metadataWriter.WriteElementString("DefualtValue", currentAttribute.DefaultValue.ToString());
}
// Write the Description if it is set.
if (currentAttribute.Description != null &&
currentAttribute.Description.UserLocLabel != null)
{
metadataWriter.WriteElementString("Description", currentAttribute.Description.UserLocLabel.Label);
}
// Write Type Specific Attribute Information using helper functions.
Type attributeType = currentAttribute.GetType();
if (attributeType == typeof(DecimalAttributeMetadata))
{
writeDecimalAttribute((DecimalAttributeMetadata)currentAttribute, metadataWriter);
}
else if (attributeType == typeof(FloatAttributeMetadata))
{
writeFloatAttribute((FloatAttributeMetadata)currentAttribute, metadataWriter);
}
else if (attributeType == typeof(IntegerAttributeMetadata))
{
writeIntegerAttribute((IntegerAttributeMetadata)currentAttribute, metadataWriter);
}
else if (attributeType == typeof(MoneyAttributeMetadata))
{
writeMoneyAttribute((MoneyAttributeMetadata)currentAttribute, metadataWriter);
}
else if (attributeType == typeof(PicklistAttributeMetadata))
{
writePicklistAttribute((PicklistAttributeMetadata)currentAttribute, metadataWriter);
}
else if (attributeType == typeof(StateAttributeMetadata))
{
writeStateAttribute((StateAttributeMetadata)currentAttribute, metadataWriter);
}
else if (attributeType == typeof(StatusAttributeMetadata))
{
writeStatusAttribute((StatusAttributeMetadata)currentAttribute, metadataWriter);
}
else if (attributeType == typeof(StringAttributeMetadata))
{
writeStringAttribute((StringAttributeMetadata)currentAttribute, metadataWriter);
}
// End Attribute Node
metadataWriter.WriteEndElement();
}
// End Attributes Node
metadataWriter.WriteEndElement();
#endregion
#region References From
metadataWriter.WriteStartElement("OneToMany");
// Get Current ReferencesFrom
foreach (OneToManyMetadata currentRelationship in currentEntity.OneToManyRelationships)
{
// Start ReferencesFrom Node
metadataWriter.WriteStartElement("From");
metadataWriter.WriteElementString("Name", currentRelationship.SchemaName);
metadataWriter.WriteElementString("IsCustomRelationship", currentRelationship.IsCustomRelationship.ToString());
metadataWriter.WriteElementString("ReferencedEntity", currentRelationship.ReferencedEntity);
metadataWriter.WriteElementString("ReferencingEntity", currentRelationship.ReferencingEntity);
metadataWriter.WriteElementString("ReferencedAttribute", currentRelationship.ReferencedAttribute);
metadataWriter.WriteElementString("ReferencingAttribute", currentRelationship.ReferencingAttribute);
// End ReferencesFrom Node
metadataWriter.WriteEndElement();
}
metadataWriter.WriteEndElement();
#endregion
#region References To
metadataWriter.WriteStartElement("ManyToOne");
foreach (OneToManyMetadata currentRelationship in currentEntity.ManyToOneRelationships)
{
// Start ReferencesFrom Node
metadataWriter.WriteStartElement("To");
metadataWriter.WriteElementString("Name", currentRelationship.SchemaName);
metadataWriter.WriteElementString("IsCustomRelationship", currentRelationship.IsCustomRelationship.ToString());
metadataWriter.WriteElementString("ReferencedEntity", currentRelationship.ReferencedEntity);
metadataWriter.WriteElementString("ReferencingEntity", currentRelationship.ReferencingEntity);
metadataWriter.WriteElementString("ReferencedAttribute", currentRelationship.ReferencedAttribute);
metadataWriter.WriteElementString("ReferencingAttribute", currentRelationship.ReferencingAttribute);
// End ReferencesFrom Node
metadataWriter.WriteEndElement();
}
metadataWriter.WriteEndElement();
#endregion
// End Entity Node
metadataWriter.WriteEndElement();
}
// End Metadata Xml Node
metadataWriter.WriteEndElement();
metadataWriter.WriteEndDocument();
// Close xml writer.
metadataWriter.Close();
}
#region check success
if (metadata.CrmMetadata.Length > 0)
{
success = true;
}
#endregion
}
catch (System.Web.Services.Protocols.SoapException)
{
// Add your error handling code here.
}
return success;
}
#region Specific Attribute Helper Functions
// Writes the Decimal Specific Attributes
private static void writeDecimalAttribute (DecimalAttributeMetadata attribute, XmlTextWriter writer)
{
writer.WriteElementString("MinValue", attribute.MinValue.ToString());
writer.WriteElementString("MaxValue", attribute.MaxValue.ToString());
writer.WriteElementString("Precision", attribute.Precision.ToString());
}
// Writes the Float Specific Attributes
private static void writeFloatAttribute (FloatAttributeMetadata attribute, XmlTextWriter writer)
{
writer.WriteElementString("MinValue", attribute.MinValue.ToString());
writer.WriteElementString("MaxValue", attribute.MaxValue.ToString());
writer.WriteElementString("Precision", attribute.Precision.ToString());
}
// Writes the Integer Specific Attributes
private static void writeIntegerAttribute (IntegerAttributeMetadata attribute, XmlTextWriter writer)
{
writer.WriteElementString("MinValue", attribute.MinValue.ToString());
writer.WriteElementString("MaxValue", attribute.MaxValue.ToString());
}
// Writes the Money Specific Attributes
private static void writeMoneyAttribute (MoneyAttributeMetadata attribute, XmlTextWriter writer)
{
writer.WriteElementString("MinValue", attribute.MinValue.ToString());
writer.WriteElementString("MaxValue", attribute.MaxValue.ToString());
writer.WriteElementString("Precision", attribute.Precision.ToString());
}
// Writes the Picklist Specific Attributes
private static void writePicklistAttribute (PicklistAttributeMetadata attribute, XmlTextWriter writer)
{
// Writes the picklist's options
writer.WriteStartElement("Options");
// Writes the attributes of each picklist option
for (int i = 0; i < attribute.Options.Length; i++)
{
writer.WriteStartElement("Option");
writer.WriteElementString("OptionValue", attribute.Options[i].Value.ToString());
writer.WriteElementString("Description", attribute.Options[i].Label.UserLocLabel.Label);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
// Writes the State Specific Attributes
private static void writeStateAttribute (StateAttributeMetadata attribute, XmlTextWriter writer)
{
// Writes the state's options
writer.WriteStartElement("Options");
// Writes the attributes of each picklist option
for (int i = 0; i < attribute.Options.Length; i++)
{
writer.WriteStartElement("Option");
writer.WriteElementString("OptionValue", attribute.Options[i].Value.ToString());
writer.WriteElementString("Description", attribute.Options[i].Label.UserLocLabel.Label);
writer.WriteElementString("DefaultStatus", attribute.Options[i].DefaultStatus.ToString());
writer.WriteEndElement();
}
writer.WriteEndElement();
}
// Writes the Status Specific Attributes
private static void writeStatusAttribute (StatusAttributeMetadata attribute, XmlTextWriter writer)
{
// Writes the status's options
writer.WriteStartElement("Options");
// Writes the attributes of each picklist option
for (int i = 0; i < attribute.Options.Length; i++)
{
writer.WriteStartElement("Option");
writer.WriteElementString("OptionValue", attribute.Options[i].Value.ToString());
writer.WriteElementString("Description", attribute.Options[i].Label.UserLocLabel.Label);
writer.WriteElementString("State", attribute.Options[i].State.ToString());
writer.WriteEndElement();
}
writer.WriteEndElement();
}
// Writes the String Specific Attributes
private static void writeStringAttribute (StringAttributeMetadata attribute, XmlTextWriter writer)
{
writer.WriteElementString("MaxLength", attribute.MaxLength.ToString());
}
#endregion
}
}
[Visual Basic .NET]
Imports System
Imports System.Xml.Serialization
Imports System.Xml
Imports System.IO
Imports Microsoft.Crm.Sdk.Utility
Imports CrmSdk
Imports MetadataServiceSdk
Namespace Microsoft.Crm.Sdk.HowTo
'/ <summary>
'/ This sample shows how to retrieve all the metadata and write it to a file.
'/ </summary>
Public Class HowToMetaData
Sub Main()
' TODO: Change the server URL and Organization to match your CRM Server and CRM Organization
SerializeAndDeserialize.Run("https://localhost:5555", "CRM_SDK")
End Sub
Public Shared Function Run(ByVal crmServerUrl As String, ByVal orgName As String) As Boolean
' Standard MetaData Service Setup
Dim service As MetadataService = CrmServiceUtility.GetMetadataService(crmServerUrl, orgName)
' Setup Data Required for Me Sample
Dim success As Boolean = False
Try
' Retrieve the Metadata
Dim request As RetrieveAllEntitiesRequest = New RetrieveAllEntitiesRequest()
request.MetadataItems = MetadataItems.All
Dim metadata As RetrieveAllEntitiesResponse = CType(service.Execute(request), RetrieveAllEntitiesResponse)
' Create an instance of StreamWriter to write text to a file.
' The using statement also closes the StreamWriter.
Dim sw As New StreamWriter("testfile.xml")
Try
' Create Xml Writer.
Dim metadataWriter As New XmlTextWriter(sw)
' Start Xml File.
metadataWriter.WriteStartDocument()
' Metadata Xml Node.
metadataWriter.WriteStartElement("Metadata")
Dim currentAttribute As AttributeMetadata ' Declared outside of loop
' Iterate through all entities and add their attributes and relationships to the file.
Dim currentEntity As EntityMetadata
For Each currentEntity In metadata.CrmMetadata
' Start Entity Node
metadataWriter.WriteStartElement("Entity")
' Write the Entity's Information.
metadataWriter.WriteElementString("Name", currentEntity.LogicalName)
If Not currentEntity.DisplayName.UserLocLabel Is Nothing Then
metadataWriter.WriteElementString("DisplayName", currentEntity.DisplayName.UserLocLabel.Label)
Else
metadataWriter.WriteElementString("DisplayName", "[NONE]")
End If
If Not currentEntity.DisplayCollectionName.UserLocLabel Is Nothing Then
metadataWriter.WriteElementString("DisplayCollectionName", currentEntity.DisplayCollectionName.UserLocLabel.Label)
Else
metadataWriter.WriteElementString("DisplayCollectionName", "[NONE]")
End If
metadataWriter.WriteElementString("IsCustomEntity", currentEntity.IsCustomEntity.ToString())
metadataWriter.WriteElementString("IsCustomizable", currentEntity.IsCustomizable.ToString())
metadataWriter.WriteElementString("ReportViewName", currentEntity.ReportViewName)
metadataWriter.WriteElementString("PrimaryField", currentEntity.PrimaryField)
metadataWriter.WriteElementString("PrimaryKey", currentEntity.PrimaryKey)
'---- Attributes -------------------------------------------------------
' Write Entity's Attributes.
metadataWriter.WriteStartElement("Attributes")
Dim j As Integer
For j = 0 To currentEntity.Attributes.Length- 1 Step j + 1
' Get Current Attribute.
currentAttribute = currentEntity.Attributes(j)
' Start Attribute Node
metadataWriter.WriteStartElement("Attribute")
' Write Attribute's information.
metadataWriter.WriteElementString("Name", currentAttribute.LogicalName)
metadataWriter.WriteElementString("Type", currentAttribute.AttributeType.ToString())
If Not currentAttribute.DisplayName.UserLocLabel Is Nothing Then
metadataWriter.WriteElementString("DisplayName", currentAttribute.DisplayName.UserLocLabel.Label)
Else
metadataWriter.WriteElementString("DisplayName", "[NONE]")
End If
metadataWriter.WriteElementString("Description", currentAttribute.IsCustomField.ToString())
metadataWriter.WriteElementString("IsCustomField", currentAttribute.IsCustomField.ToString())
metadataWriter.WriteElementString("RequiredLevel", currentAttribute.RequiredLevel.ToString())
metadataWriter.WriteElementString("ValidForCreate", currentAttribute.ValidForCreate.ToString())
metadataWriter.WriteElementString("ValidForRead", currentAttribute.ValidForRead.ToString())
metadataWriter.WriteElementString("ValidForUpdate", currentAttribute.ValidForUpdate.ToString())
' Write the Default Value if it is set.
If Not currentAttribute.DefaultValue Is Nothing Then
metadataWriter.WriteElementString("DefualtValue", currentAttribute.DefaultValue.ToString())
End If
' Write the Description if it is set.
If (currentAttribute.Description IsNot Nothing And currentAttribute.Description.UserLocLabel IsNot Nothing) Then
metadataWriter.WriteElementString("Description", currentAttribute.Description.UserLocLabel.Label)
End If
' Write the Type Specific Attribute Information using helper functions.
Dim attributeType As Type = currentAttribute.GetType()
If attributeType Is GetType(DecimalAttributeMetadata) Then
writeDecimalAttribute(CType(currentAttribute, DecimalAttributeMetadata), metadataWriter)
ElseIf attributeType Is GetType(FloatAttributeMetadata) Then
writeFloatAttribute(CType(currentAttribute, FloatAttributeMetadata), metadataWriter)
ElseIf attributeType Is GetType(IntegerAttributeMetadata) Then
writeIntegerAttribute(CType(currentAttribute, IntegerAttributeMetadata), metadataWriter)
ElseIf attributeType Is GetType(MoneyAttributeMetadata) Then
writeMoneyAttribute(CType(currentAttribute, MoneyAttributeMetadata), metadataWriter)
ElseIf attributeType Is GetType(PicklistAttributeMetadata) Then
writePicklistAttribute(CType(currentAttribute, PicklistAttributeMetadata), metadataWriter)
ElseIf attributeType Is GetType(StateAttributeMetadata) Then
writeStateAttribute(CType(currentAttribute, StateAttributeMetadata), metadataWriter)
ElseIf attributeType Is GetType(StatusAttributeMetadata) Then
writeStatusAttribute(CType(currentAttribute, StatusAttributeMetadata), metadataWriter)
ElseIf attributeType Is GetType(StringAttributeMetadata) Then
writeStringAttribute(CType(currentAttribute, StringAttributeMetadata), metadataWriter)
End If
' End Attribute Node
metadataWriter.WriteEndElement()
Next
' End Attributes Node
metadataWriter.WriteEndElement()
'-----------------------------------------------------------------------
'---- References To ----------------------------------------------------
metadataWriter.WriteStartElement("OneToMany")
' Get Current ReferencesFrom
Dim currentRelationship As OneToManyMetadata
For Each currentRelationship In currentEntity.OneToManyRelationships
' Start ReferencesFrom Node
metadataWriter.WriteStartElement("From")
metadataWriter.WriteElementString("Name", currentRelationship.SchemaName)
metadataWriter.WriteElementString("IsCustomRelationship", currentRelationship.IsCustomRelationship.ToString())
metadataWriter.WriteElementString("ReferencedEntity", currentRelationship.ReferencedEntity)
metadataWriter.WriteElementString("ReferencingEntity", currentRelationship.ReferencingEntity)
metadataWriter.WriteElementString("ReferencedAttribute", currentRelationship.ReferencedAttribute)
metadataWriter.WriteElementString("ReferencingAttribute", currentRelationship.ReferencingAttribute)
' End ReferencesFrom Node
metadataWriter.WriteEndElement()
Next
metadataWriter.WriteEndElement()
'-----------------------------------------------------------------------
' End Entity Node
'---- References To ----------------------------------------------------
metadataWriter.WriteStartElement("ManyToOne")
For Each currentRelationship In currentEntity.ManyToOneRelationships
' Start ReferencesFrom Node
metadataWriter.WriteStartElement("To")
metadataWriter.WriteElementString("Name", currentRelationship.SchemaName)
metadataWriter.WriteElementString("IsCustomRelationship", currentRelationship.IsCustomRelationship.ToString())
metadataWriter.WriteElementString("ReferencedEntity", currentRelationship.ReferencedEntity)
metadataWriter.WriteElementString("ReferencingEntity", currentRelationship.ReferencingEntity)
metadataWriter.WriteElementString("ReferencedAttribute", currentRelationship.ReferencedAttribute)
metadataWriter.WriteElementString("ReferencingAttribute", currentRelationship.ReferencingAttribute)
' End ReferencesFrom Node
metadataWriter.WriteEndElement()
Next
metadataWriter.WriteEndElement()
'-----------------------------------------------------------------------
' End Entity Node
metadataWriter.WriteEndElement()
Next
' End Metadata Xml Node
metadataWriter.WriteEndElement()
metadataWriter.WriteEndDocument()
' Close XML writer
metadataWriter.Close()
Finally
sw.Close()
End Try
'---- check success ----------------------------------------------------
If metadata.CrmMetadata.Length > 0 Then
success = True
End If
'-----------------------------------------------------------------------
Catch
' Add your error handling code here.
End Try
Return success
End Function
#Region "Specific Attribute Helper Functions"
' Writes the Decimal Specific Attributes
Private Shared Sub writeDecimalAttribute(attribute As DecimalAttributeMetadata, writer As XmlTextWriter)
writer.WriteElementString("MinValue", attribute.MinValue.ToString())
writer.WriteElementString("MaxValue", attribute.MaxValue.ToString())
writer.WriteElementString("Precision", attribute.Precision.ToString())
End Sub 'writeDecimalAttribute
' Writes the Float Specific Attributes
Private Shared Sub writeFloatAttribute(attribute As FloatAttributeMetadata, writer As XmlTextWriter)
writer.WriteElementString("MinValue", attribute.MinValue.ToString())
writer.WriteElementString("MaxValue", attribute.MaxValue.ToString())
writer.WriteElementString("Precision", attribute.Precision.ToString())
End Sub 'writeFloatAttribute
' Writes the Integer Specific Attributes
Private Shared Sub writeIntegerAttribute(attribute As IntegerAttributeMetadata, writer As XmlTextWriter)
writer.WriteElementString("MinValue", attribute.MinValue.ToString())
writer.WriteElementString("MaxValue", attribute.MaxValue.ToString())
End Sub 'writeIntegerAttribute
' Writes the Money Specific Attributes
Private Shared Sub writeMoneyAttribute(attribute As MoneyAttributeMetadata, writer As XmlTextWriter)
writer.WriteElementString("MinValue", attribute.MinValue.ToString())
writer.WriteElementString("MaxValue", attribute.MaxValue.ToString())
writer.WriteElementString("Precision", attribute.Precision.ToString())
End Sub 'writeMoneyAttribute
' Writes the Picklist Specific Attributes
Private Shared Sub writePicklistAttribute(attribute As PicklistAttributeMetadata, writer As XmlTextWriter)
' Writes the picklist's options
writer.WriteStartElement("Options")
' Writes the attributes of each picklist option
Dim i As Integer
For i = 0 To attribute.Options.Length - 1
writer.WriteStartElement("Option")
writer.WriteElementString("OptionValue", attribute.Options(i).Value.ToString())
writer.WriteElementString("Description", attribute.Options(i).Label.UserLocLabel.Label)
writer.WriteEndElement()
Next i
writer.WriteEndElement()
End Sub 'writePicklistAttribute
' Writes the State Specific Attributes
Private Shared Sub writeStateAttribute(attribute As StateAttributeMetadata, writer As XmlTextWriter)
' Writes the state's options
writer.WriteStartElement("Options")
' Writes the attributes of each picklist option
Dim i As Integer
For i = 0 To attribute.Options.Length - 1
writer.WriteStartElement("Option")
writer.WriteElementString("OptionValue", attribute.Options(i).Value.ToString())
writer.WriteElementString("Description", attribute.Options(i).Label.UserLocLabel.Label)
writer.WriteElementString("DefaultStatus", attribute.Options(i).DefaultStatus.ToString())
writer.WriteEndElement()
Next i
writer.WriteEndElement()
End Sub 'writeStateAttribute
' Writes the Status Specific Attributes
Private Shared Sub writeStatusAttribute(attribute As StatusAttributeMetadata, writer As XmlTextWriter)
' Writes the status's options
writer.WriteStartElement("Options")
' Writes the attributes of each picklist option
Dim i As Integer
For i = 0 To attribute.Options.Length - 1
writer.WriteStartElement("Option")
writer.WriteElementString("OptionValue", attribute.Options(i).Value.ToString())
writer.WriteElementString("Description", attribute.Options(i).Label.UserLocLabel.Label)
writer.WriteElementString("State", attribute.Options(i).State.ToString())
writer.WriteEndElement()
Next i
writer.WriteEndElement()
End Sub 'writeStatusAttribute
' Writes the String Specific Attributes
Private Shared Sub writeStringAttribute(attribute As StringAttributeMetadata, writer As XmlTextWriter)
writer.WriteElementString("MaxLength", attribute.MaxLength.ToString())
End Sub 'writeStringAttribute
#End Region
End Class 'HowToMetaData
End Namespace 'Microsoft.Crm.Sdk.HowTo
.gif)