ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Core.Data.DDL Namespace / FieldDescription Class / CreateStringField Method
The name of the ArcGIS.Core.Data.Field to create.
The length of the ArcGIS.Core.Data.Field to create.
Example Version

CreateStringField Method
Creates a field description for a string ArcGIS.Core.Data.Field.
Syntax
public static FieldDescription CreateStringField( 
   string name,
   int length
)

Parameters

name
The name of the ArcGIS.Core.Data.Field to create.
length
The length of the ArcGIS.Core.Data.Field to create.

Return Value

A field description for a string ArcGIS.Core.Data.Field.
Example
Creating a Table
public void CreateTableSnippet(Geodatabase geodatabase, CodedValueDomain inspectionResultsDomain)
{
    // Create a PoleInspection table with the following fields
    //  GlobalID
    //  ObjectID
    //  InspectionDate (date)
    //  InspectionResults (pre-existing InspectionResults coded value domain)
    //  InspectionNotes (string)

    // This static helper routine creates a FieldDescription for a GlobalID field with default values
    FieldDescription globalIDFieldDescription = FieldDescription.CreateGlobalIDField();

    // This static helper routine creates a FieldDescription for an ObjectID field with default values
    FieldDescription objectIDFieldDescription = FieldDescription.CreateObjectIDField();

    // Create a FieldDescription for the InspectionDate field
    FieldDescription inspectionDateFieldDescription = new FieldDescription("InspectionDate", FieldType.Date)
    {
        AliasName = "Inspection Date"
    };

    // This static helper routine creates a FieldDescription for a Domain field (from a pre-existing domain)
    FieldDescription inspectionResultsFieldDescription = FieldDescription.CreateDomainField("InspectionResults", new CodedValueDomainDescription(inspectionResultsDomain));
    inspectionResultsFieldDescription.AliasName = "Inspection Results";

    // This static helper routine creates a FieldDescription for a string field
    FieldDescription inspectionNotesFieldDescription = FieldDescription.CreateStringField("InspectionNotes", 512);
    inspectionNotesFieldDescription.AliasName = "Inspection Notes";

    // Assemble a list of all of our field descriptions
    List<FieldDescription> fieldDescriptions = new List<FieldDescription>()
{ globalIDFieldDescription, objectIDFieldDescription, inspectionDateFieldDescription, inspectionResultsFieldDescription, inspectionNotesFieldDescription };

    // Create a TableDescription object to describe the table to create
    TableDescription tableDescription = new TableDescription("PoleInspection", fieldDescriptions);

    // Create a SchemaBuilder object
    SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);

    // Add the creation of PoleInspection to our list of DDL tasks
    schemaBuilder.Create(tableDescription);

    // Execute the DDL
    bool success = schemaBuilder.Build();

    // Inspect error messages
    if (!success)
    {
        IReadOnlyList<string> errorMessages = schemaBuilder.ErrorMessages;
        //etc.
    }
}
Creating a feature class
public void CreateFeatureClassSnippet(Geodatabase geodatabase, FeatureClass existingFeatureClass, SpatialReference spatialReference)
{
    // Create a Cities feature class with the following fields
    //  GlobalID
    //  ObjectID
    //  Name (string)
    //  Population (integer)

    // This static helper routine creates a FieldDescription for a GlobalID field with default values
    FieldDescription globalIDFieldDescription = FieldDescription.CreateGlobalIDField();

    // This static helper routine creates a FieldDescription for an ObjectID field with default values
    FieldDescription objectIDFieldDescription = FieldDescription.CreateObjectIDField();

    // This static helper routine creates a FieldDescription for a string field
    FieldDescription nameFieldDescription = FieldDescription.CreateStringField("Name", 255);

    // This static helper routine creates a FieldDescription for an integer field
    FieldDescription populationFieldDescription = FieldDescription.CreateIntegerField("Population");

    // Assemble a list of all of our field descriptions
    List<FieldDescription> fieldDescriptions = new List<FieldDescription>()
{ globalIDFieldDescription, objectIDFieldDescription, nameFieldDescription, populationFieldDescription };

    // Create a ShapeDescription object
    ShapeDescription shapeDescription = new ShapeDescription(GeometryType.Point, spatialReference);

    // Alternatively, ShapeDescriptions can be created from another feature class.  In this case, the new feature class will inherit the same shape properties of the existing class
    ShapeDescription alternativeShapeDescription = new ShapeDescription(existingFeatureClass.GetDefinition());

    // Create a FeatureClassDescription object to describe the feature class to create
    FeatureClassDescription featureClassDescription =
      new FeatureClassDescription("Cities", fieldDescriptions, shapeDescription);

    // Create a SchemaBuilder object
    SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);

    // Add the creation of the Cities feature class to our list of DDL tasks
    schemaBuilder.Create(featureClassDescription);

    // Execute the DDL
    bool success = schemaBuilder.Build();

    // Inspect error messages
    if (!success)
    {
        IReadOnlyList<string> errorMessages = schemaBuilder.ErrorMessages;
        //etc.
    }
}
Adding fields to a FeatureClass
public void AddFieldsInFeatureClassSnippet(Geodatabase geodatabase)
{
    // Adding following fields to the 'Parcels' FeatureClass
    // Global ID
    // Parcel_ID
    // Tax_Code
    // Parcel_Address

    // The FeatureClass to add fields
    string featureClassName = "Parcels";

    FeatureClassDefinition originalFeatureClassDefinition = geodatabase.GetDefinition<FeatureClassDefinition>(featureClassName);
    FeatureClassDescription originalFeatureClassDescription = new FeatureClassDescription(originalFeatureClassDefinition);

    // The four new fields to add on the 'Parcels' FeatureClass
    FieldDescription globalIdField = FieldDescription.CreateGlobalIDField();
    FieldDescription parcelIdDescription = new FieldDescription("Parcel_ID", FieldType.GUID);
    FieldDescription taxCodeDescription = FieldDescription.CreateIntegerField("Tax_Code");
    FieldDescription addressDescription = FieldDescription.CreateStringField("Parcel_Address", 150);

    List<FieldDescription> fieldsToAdd = new List<FieldDescription> { globalIdField, parcelIdDescription,
taxCodeDescription, addressDescription };

    // Add new fields on the new FieldDescription list
    List<FieldDescription> modifiedFieldDescriptions = new List<FieldDescription>(originalFeatureClassDescription.FieldDescriptions);
    modifiedFieldDescriptions.AddRange(fieldsToAdd);

    // The new FeatureClassDescription with additional fields
    FeatureClassDescription modifiedFeatureClassDescription = new FeatureClassDescription(originalFeatureClassDescription.Name,
      modifiedFieldDescriptions, originalFeatureClassDescription.ShapeDescription);

    SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);

    // Update the 'Parcels' FeatureClass with newly added fields
    schemaBuilder.Modify(modifiedFeatureClassDescription);
    bool modifyStatus = schemaBuilder.Build();

    if (!modifyStatus)
    {
        IReadOnlyList<string> errors = schemaBuilder.ErrorMessages;
    }
}
Creating an annotation feature class
public void CreateStandAloneAnnotationFeatureClass(Geodatabase geodatabase, SpatialReference spatialReference)
{
    // Creating a Cities annotation feature class
    // with following user defined fields
    // Name 
    // GlobalID

    // Annotation feature class name
    string annotationFeatureClassName = "CitiesAnnotation";

    // Create user defined attribute fields for annotation feature class 
    FieldDescription globalIDFieldDescription = FieldDescription.CreateGlobalIDField();
    FieldDescription nameFieldDescription = FieldDescription.CreateStringField("Name", 255);

    // Create a list of all field descriptions
    List<FieldDescription> fieldDescriptions = new List<FieldDescription> { globalIDFieldDescription, nameFieldDescription };

    // Create a ShapeDescription object
    ShapeDescription shapeDescription = new ShapeDescription(GeometryType.Polygon, spatialReference);

    // Create general placement properties for Maplex engine 
    CIMMaplexGeneralPlacementProperties generalPlacementProperties =
      new CIMMaplexGeneralPlacementProperties
      {
          AllowBorderOverlap = true,
          PlacementQuality = MaplexQualityType.High,
          DrawUnplacedLabels = true,
          InvertedLabelTolerance = 1.0,
          RotateLabelWithDisplay = true,
          UnplacedLabelColor = new CIMRGBColor
          {
              R = 0,
              G = 255,
              B = 0,
              Alpha = 0.5f // Green
          }
      };

    // Create general placement properties for Standard engine

    //CIMStandardGeneralPlacementProperties generalPlacementProperties =
    //  new CIMStandardGeneralPlacementProperties
    //  {
    //    DrawUnplacedLabels = true,
    //    InvertedLabelTolerance = 3.0,
    //    RotateLabelWithDisplay = true,
    //    UnplacedLabelColor = new CIMRGBColor
    //    {
    //      R = 255, G = 0, B = 0, Alpha = 0.5f // Red
    //    } 
    //   };


    // Create annotation  label classes
    // Green label
    CIMLabelClass greenLabelClass = new CIMLabelClass
    {
        Name = "Green",
        ExpressionTitle = "Expression-Green",
        ExpressionEngine = LabelExpressionEngine.Arcade,
        Expression = "$feature.OBJECTID",
        ID = 1,
        Priority = 0,
        Visibility = true,
        TextSymbol = new CIMSymbolReference
        {
            Symbol = new CIMTextSymbol()
            {
                Angle = 45,
                FontType = FontType.Type1,
                FontFamilyName = "Tahoma",
                FontEffects = FontEffects.Normal,
                HaloSize = 2.0,

                Symbol = new CIMPolygonSymbol
                {
                    SymbolLayers = new CIMSymbolLayer[]
            {
        new CIMSolidFill
        {
          Color = CIMColor.CreateRGBColor(0, 255, 0)
        }
            },
                    UseRealWorldSymbolSizes = true
                }
            },
            MaxScale = 0,
            MinScale = 0,
            SymbolName = "TextSymbol-Green"
        },
        StandardLabelPlacementProperties = new CIMStandardLabelPlacementProperties
        {
            AllowOverlappingLabels = true,
            LineOffset = 1.0
        },
        MaplexLabelPlacementProperties = new CIMMaplexLabelPlacementProperties
        {
            AlignLabelToLineDirection = true,
            AvoidPolygonHoles = true
        }
    };

    // Blue label
    CIMLabelClass blueLabelClass = new CIMLabelClass
    {
        Name = "Blue",
        ExpressionTitle = "Expression-Blue",
        ExpressionEngine = LabelExpressionEngine.Arcade,
        Expression = "$feature.OBJECTID",
        ID = 2,
        Priority = 0,
        Visibility = true,
        TextSymbol = new CIMSymbolReference
        {
            Symbol = new CIMTextSymbol()
            {
                Angle = 45,
                FontType = FontType.Type1,
                FontFamilyName = "Consolas",
                FontEffects = FontEffects.Normal,
                HaloSize = 2.0,

                Symbol = new CIMPolygonSymbol
                {
                    SymbolLayers = new CIMSymbolLayer[]
            {
        new CIMSolidFill
        {
          Color = CIMColor.CreateRGBColor(0, 0, 255)
        }
            },
                    UseRealWorldSymbolSizes = true
                }
            },
            MaxScale = 0,
            MinScale = 0,
            SymbolName = "TextSymbol-Blue"
        },
        StandardLabelPlacementProperties = new CIMStandardLabelPlacementProperties
        {
            AllowOverlappingLabels = true,
            LineOffset = 1.0
        },
        MaplexLabelPlacementProperties = new CIMMaplexLabelPlacementProperties
        {
            AlignLabelToLineDirection = true,
            AvoidPolygonHoles = true
        }
    };

    // Create a list of labels
    List<CIMLabelClass> labelClasses = new List<CIMLabelClass> { greenLabelClass, blueLabelClass };

    // Create an annotation feature class description object to describe the feature class to create
    AnnotationFeatureClassDescription annotationFeatureClassDescription =
      new AnnotationFeatureClassDescription(annotationFeatureClassName, fieldDescriptions, shapeDescription,
        generalPlacementProperties, labelClasses)
      {
          IsAutoCreate = true,
          IsSymbolIDRequired = false,
          IsUpdatedOnShapeChange = true
      };

    // Create a SchemaBuilder object
    SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);

    // Add the creation of the Cities annotation feature class to the list of DDL tasks
    schemaBuilder.Create(annotationFeatureClassDescription);

    // Execute the DDL
    bool success = schemaBuilder.Build();

    // Inspect error messages
    if (!success)
    {
        IReadOnlyList<string> errorMessages = schemaBuilder.ErrorMessages;
        //etc.
    }
}
Creating a feature-linked annotation feature class
public void CreateFeatureLinkedAnnotationFeatureClass(Geodatabase geodatabase, SpatialReference spatialReference)
{
    // Creating a feature-linked annotation feature class between water pipe and valve in water distribution network
    // with following user defined fields
    // PipeName 
    // GlobalID

    // Annotation feature class name
    string annotationFeatureClassName = "WaterPipeAnnotation";

    // Create user defined attribute fields for annotation feature class
    FieldDescription pipeGlobalID = FieldDescription.CreateGlobalIDField();
    FieldDescription nameFieldDescription = FieldDescription.CreateStringField("Name", 255);

    // Create a list of all field descriptions
    List<FieldDescription> fieldDescriptions = new List<FieldDescription> { pipeGlobalID, nameFieldDescription };

    // Create a ShapeDescription object
    ShapeDescription shapeDescription = new ShapeDescription(GeometryType.Polygon, spatialReference);

    // Create general placement properties for Maplex engine 
    CIMMaplexGeneralPlacementProperties generalPlacementProperties = new CIMMaplexGeneralPlacementProperties
    {
        AllowBorderOverlap = true,
        PlacementQuality = MaplexQualityType.High,
        DrawUnplacedLabels = true,
        InvertedLabelTolerance = 1.0,
        RotateLabelWithDisplay = true,
        UnplacedLabelColor = new CIMRGBColor
        {
            R = 255,
            G = 0,
            B = 0,
            Alpha = 0.5f
        }
    };

    // Create annotation  label classes
    // Green label
    CIMLabelClass greenLabelClass = new CIMLabelClass
    {
        Name = "Green",
        ExpressionTitle = "Expression-Green",
        ExpressionEngine = LabelExpressionEngine.Arcade,
        Expression = "$feature.OBJECTID",
        ID = 1,
        Priority = 0,
        Visibility = true,
        TextSymbol = new CIMSymbolReference
        {
            Symbol = new CIMTextSymbol()
            {
                Angle = 45,
                FontType = FontType.Type1,
                FontFamilyName = "Tahoma",
                FontEffects = FontEffects.Normal,
                HaloSize = 2.0,

                Symbol = new CIMPolygonSymbol
                {
                    SymbolLayers = new CIMSymbolLayer[]
            {
        new CIMSolidFill
        {
          Color = CIMColor.CreateRGBColor(0, 255, 0)
        }
            },
                    UseRealWorldSymbolSizes = true
                }
            },
            MaxScale = 0,
            MinScale = 0,
            SymbolName = "TextSymbol-Green"
        },
        StandardLabelPlacementProperties = new CIMStandardLabelPlacementProperties
        {
            AllowOverlappingLabels = true,
            LineOffset = 1.0
        },
        MaplexLabelPlacementProperties = new CIMMaplexLabelPlacementProperties
        {
            AlignLabelToLineDirection = true,
            AvoidPolygonHoles = true
        }
    };

    // Blue label
    CIMLabelClass blueLabelClass = new CIMLabelClass
    {
        Name = "Blue",
        ExpressionTitle = "Expression-Blue",
        ExpressionEngine = LabelExpressionEngine.Arcade,
        Expression = "$feature.OBJECTID",
        ID = 2,
        Priority = 0,
        Visibility = true,
        TextSymbol = new CIMSymbolReference
        {
            Symbol = new CIMTextSymbol()
            {
                Angle = 45,
                FontType = FontType.Type1,
                FontFamilyName = "Consolas",
                FontEffects = FontEffects.Normal,
                HaloSize = 2.0,

                Symbol = new CIMPolygonSymbol
                {
                    SymbolLayers = new CIMSymbolLayer[]
            {
        new CIMSolidFill
        {
          Color = CIMColor.CreateRGBColor(0, 0, 255)
        }
            },
                    UseRealWorldSymbolSizes = true
                }
            },
            MaxScale = 0,
            MinScale = 0,
            SymbolName = "TextSymbol-Blue"
        },
        StandardLabelPlacementProperties = new CIMStandardLabelPlacementProperties
        {
            AllowOverlappingLabels = true,
            LineOffset = 1.0
        },
        MaplexLabelPlacementProperties = new CIMMaplexLabelPlacementProperties
        {
            AlignLabelToLineDirection = true,
            AvoidPolygonHoles = true
        }
    };

    // Create a list of labels
    List<CIMLabelClass> labelClasses = new List<CIMLabelClass> { greenLabelClass, blueLabelClass };


    // Create linked feature description
    // Linked feature class name
    string linkedFeatureClassName = "WaterPipe";

    // Create fields for water pipe
    FieldDescription waterPipeGlobalID = FieldDescription.CreateGlobalIDField();
    FieldDescription pipeName = FieldDescription.CreateStringField("PipeName", 255);

    // Create a list of water pipe field descriptions
    List<FieldDescription> pipeFieldDescriptions = new List<FieldDescription> { waterPipeGlobalID, pipeName };

    // Create a linked feature class description
    FeatureClassDescription linkedFeatureClassDescription = new FeatureClassDescription(linkedFeatureClassName, pipeFieldDescriptions,
      new ShapeDescription(GeometryType.Polyline, spatialReference));

    // Create a SchemaBuilder object
    SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);

    // Add the creation of the linked feature class to the list of DDL tasks
    FeatureClassToken linkedFeatureClassToken = schemaBuilder.Create(linkedFeatureClassDescription);

    // Create an annotation feature class description object to describe the feature class to create
    AnnotationFeatureClassDescription annotationFeatureClassDescription =
      new AnnotationFeatureClassDescription(annotationFeatureClassName, fieldDescriptions, shapeDescription,
        generalPlacementProperties, labelClasses, new FeatureClassDescription(linkedFeatureClassToken))
      {
          IsAutoCreate = true,
          IsSymbolIDRequired = false,
          IsUpdatedOnShapeChange = true
      };

    // Add the creation of the annotation feature class to the list of DDL tasks
    schemaBuilder.Create(annotationFeatureClassDescription);

    // Execute the DDL
    bool success = schemaBuilder.Build();

    // Inspect error messages
    if (!success)
    {
        IReadOnlyList<string> errorMessages = schemaBuilder.ErrorMessages;
        //etc.
    }
}
Requirements

Target Platforms: Windows 11, Windows 10

ArcGIS Pro version: 3 or higher.
See Also