ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Core.Data Namespace / FeatureClass Class / CreateRow Method
An RowBuffer with the field values to be set for the new feature.
Example

In This Topic
    CreateRow Method (FeatureClass)
    In This Topic
    Creates a new feature in the feature class with a system assigned object ID. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public new Feature CreateRow( 
       RowBuffer featureBuffer
    )
    Public Shadows Function CreateRow( _
       ByVal featureBuffer As RowBuffer _
    ) As Feature

    Parameters

    featureBuffer
    An RowBuffer with the field values to be set for the new feature.

    Return Value

    A populated Feature.
    Exceptions
    ExceptionDescription
    featureBuffer is null.
    A geodatabase-related exception has occurred.
    Example
    Creating a Feature
    public async Task CreatingAFeature()
    {
      string message = String.Empty;
      bool creationResult = false;
    
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
        using (FeatureClass enterpriseFeatureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.FacilitySite"))
        {
          //var geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(uri)) for a File GDB
          //
          //var shapeFileConnPath = new FileSystemConnectionPath(uri, FileSystemDatastoreType.Shapefile);
          //var shapefile = new FileSystemDatastore(shapeFileConnPath);
          //var table = shapefile.OpenDataset<Table>(strShapeFileName); for a Shape file
    
          //declare the callback here. We are not executing it yet
          EditOperation editOperation = new EditOperation();
          editOperation.Callback(context =>
          {
            FeatureClassDefinition facilitySiteDefinition = enterpriseFeatureClass.GetDefinition();
            int facilityIdIndex = facilitySiteDefinition.FindField("FACILITYID");
    
            using (RowBuffer rowBuffer = enterpriseFeatureClass.CreateRowBuffer())
            {
              // Either the field index or the field name can be used in the indexer.
              rowBuffer[facilityIdIndex] = "wMain";
              rowBuffer["NAME"] = "Griffith Park";
              rowBuffer["OWNTYPE"] = "Municipal";
              rowBuffer["FCODE"] = "Park";
              // Add it to Public Attractions Subtype.
              rowBuffer[facilitySiteDefinition.GetSubtypeField()] = 820;
    
              List<Coordinate2D> newCoordinates = new List<Coordinate2D>
              {
                  new Coordinate2D(1021570, 1880583),
                  new Coordinate2D(1028730, 1880994),
                  new Coordinate2D(1029718, 1875644),
                  new Coordinate2D(1021405, 1875397)
                };
    
              rowBuffer[facilitySiteDefinition.GetShapeField()] = new PolygonBuilderEx(newCoordinates).ToGeometry();
    
              using (Feature feature = enterpriseFeatureClass.CreateRow(rowBuffer))
              {
                //To Indicate that the attribute table has to be updated
                context.Invalidate(feature);
              }
            }
    
          }, enterpriseFeatureClass);
    
          try
          {
            creationResult = editOperation.Execute();
            if (!creationResult) message = editOperation.ErrorMessage;
          }
          catch (GeodatabaseException exObj)
          {
            message = exObj.Message;
          }
        }
      });
    
      if (!string.IsNullOrEmpty(message))
        MessageBox.Show(message);
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also