ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Editing Namespace / EditOperation Class / Create Method / Create(Table,KnowledgeGraphDocumentDescription) Method
The table representing the Document named type.
A description of the document record to create.
Example

In This Topic
    Create(Table,KnowledgeGraphDocumentDescription) Method
    In This Topic
    Creates a new row in the Knowledge Graph Document table for the specified properties in the KnowledgeGraphDocumentDescription.
    Syntax

    Parameters

    documentTable
    The table representing the Document named type.
    documentDescription
    A description of the document record to create.

    Return Value

    A RowToken object that represents the row to be created.
    Exceptions
    ExceptionDescription
    documentTable cannot be null.
    documentDescription cannot be null.
    The document path is an invalid path.
    The documentTable is not part of a Knowledge Graph, the Knowledge Graph does not support documents or documentTable is not the Knowledge Graph document type.
    Remarks
    If a document is specified, the name, url, contentType, title, fileExtension and text fields are auto populated from the document.
    Example
    Create feature from a modified inspector
    // Creates a new feature by copying and optionally modifying the attributes of an existing feature using an inspector.
    await QueuedTask.Run(() =>
        {
          // Create an inspector and load a feature
          // The inspector is used to modify the attributes of the feature before creating it
          var insp = new Inspector();
          insp.Load(featureLayer, objectId);
          // modify attributes if necessary
          // insp["Field1"] = newValue;
    
          //Create new feature from an existing inspector (copying the feature)
          var createOp = new EditOperation() { Name = "Create from insp" };
          createOp.Create(insp.MapMember, insp.ToDictionary(a => a.FieldName, a => a.CurrentValue));
    
          if (!createOp.IsEmpty)
          {
            var result = createOp.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
          }
        });
    Create features from a CSV file
    // Creates new point features in the specified feature layer using data from a CSV source.
    var csvData = new List<(double X, double Y, double StopOrder, double FacilityID)>();
    //Run on MCT
    await QueuedTask.Run(() =>
    {
      //Create the edit operation
      var createOperation = new ArcGIS.Desktop.Editing.EditOperation() { Name = "Generate points", SelectNewFeatures = false };
    
      // determine the shape field name - it may not be 'Shape' 
      string shapeField = featureLayer.GetFeatureClass().GetDefinition().GetShapeField();
    
      //Loop through csv data
      foreach (var item in csvData)
      {
    
        //Create the point geometry
        ArcGIS.Core.Geometry.MapPoint newMapPoint =
            ArcGIS.Core.Geometry.MapPointBuilderEx.CreateMapPoint(item.X, item.Y);
    
        // include the attributes via a dictionary
        var atts = new Dictionary<string, object>
          {
            { "StopOrder", item.StopOrder },
            { "FacilityID", item.FacilityID },
            { shapeField, newMapPoint }
          };
    
        // queue feature creation
        createOperation.Create(featureLayer, atts);
      }
      // execute the edit (feature creation) operation
      if (createOperation.IsEmpty)
      {
        return createOperation.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
      }
      else
        return false;
    });
    Create a record in a separate table in the Map within Row Events
    // attach an event handler to receive notifications when a new row is created in the
    // associated table of the first feature layer found in the active map. Use this method to enable custom logic in
    // response to row creation events within your ArcGIS Pro add-in.
    // subscribe to the RowCreatedEvent
    Table table = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault().GetTable();
    RowCreatedEvent.Subscribe(rowChangedEventArgs =>
      {
        // RowEvent callbacks are always called on the QueuedTask so there is no need 
        // to wrap your code within a QueuedTask.Run lambda.
    
        // get the edit operation
        var parentEditOp = rowChangedEventArgs.Operation;
    
        // set up some attributes
        var attribs = new Dictionary<string, object>
        {
          { "Layer", "Parcels" },
          { "Description", "objectId: " + rowChangedEventArgs.Row.GetObjectID().ToString() + " " + DateTime.Now.ToShortTimeString() }
        };
    
        //create a record in an audit table
        var sTable = MapView.Active.Map.FindStandaloneTables("EditHistory")[0];
        var table = sTable.GetTable();
        parentEditOp.Create(table, attribs);
      }, table);
    Create a record in a separate table within Row Events
    // Attach an event handler to the <see cref="ArcGIS.Desktop.Editing.Events.RowCreatedEvent"/> for the table associated with the first <see cref="ArcGIS.Desktop.Mapping.FeatureLayer"/> in the active map. Use this method to monitor when new rows are created
    // in that table, enabling custom logic to be executed in response to record creation events.
    Table firstTable = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault().GetTable();
    RowCreatedEvent.Subscribe(rowChangedEventArgs =>
    {
      // RowEvent callbacks are always called on the QueuedTask so there is no need 
      // to wrap your code within a QueuedTask.Run lambda.
      // update a separate table not in the map when a row is created
      // You MUST use the ArcGIS.Core.Data API to edit the table. Do NOT
      // use a new edit operation in the RowEvent callbacks
      try
      {
        // get the edit operation
        var parentEditOp = rowChangedEventArgs.Operation;
        // set up some attributes
        var attribs = new Dictionary<string, object>
          {
            { "Description", "objectId: " + rowChangedEventArgs.Row.GetObjectID().ToString() + " " + DateTime.Now.ToShortTimeString() }
          };
        // update Notes table with information about the new feature
        using var geoDatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(Project.Current.DefaultGeodatabasePath)));
        using var table = geoDatabase.OpenDataset<Table>("Notes");
        parentEditOp.Create(table, attribs);
      }
      catch (Exception e)
      {
        throw new Exception($@"Error in OnRowCreated for objectId: {rowChangedEventArgs.Row.GetObjectID()} : {e}");
      }
    }, firstTable);
    Create a Document Record 2
    {
      await QueuedTask.Run(() =>
      {
        using (var kg_for_doc = kgLayer.GetDatastore())
        {
          var propInfo = kg_for_doc.GetPropertyNameInfo();
          if (!propInfo.SupportsDocuments)
            return false;
    
          var edit_op = new EditOperation()
          {
            Name = "Create Document Example",
            SelectNewFeatures = true
          };
    
          var doc_entity_name = propInfo.DocumentTypeName;
          var hasdoc_rel_name = GetHasDocumentTypeName(kg.GetDataModel());
    
          //Document can also be FeatureClass
          var doc_tbl = kg_for_doc.OpenDataset<Table>(doc_entity_name);
          var doc_rel_tbl = kg_for_doc.OpenDataset<Table>(hasdoc_rel_name);
    
          //This is the document to be added...file, image, resource, etc.
          var doc_url = @"E:\Data\Temp\HelloWorld.txt";
    
          // create the KnowledgeGraphDocumentDescription
          var kgDocDesc = new KnowledgeGraphDocumentDescription(doc_url);
    
          // if there is a geometry use the following ctor
          // var kgDocDesc = new KnowledgeGraphDocumentDescription(doc_url, doc_location);
    
          // if you have additional custom attributes 
          //var customDocAtts = new Dictionary<string, object>();
          //customDocAtts.Add("custom_attrib", "Foo");
          //customDocAtts.Add("custom_attrib2", "Bar");
          //var kgDocDesc = new KnowledgeGraphDocumentDescription(url, null, customDocAtts);
    
          // add additional properties if required
          kgDocDesc.Keywords = @"text,file,example";
    
          // The Create method will auto-populate the Url, Name, FileExtension and contentType fields of the document row
          // from the path supplied.  
          var rowToken = edit_op.Create(doc_tbl, kgDocDesc);
    
          //Get the entity whose document this is...
          var org_fc = kg_for_doc.OpenDataset<FeatureClass>("Organization");
          var qf = new ArcGIS.Core.Data.QueryFilter()
          {
            WhereClause = "name = 'Acme'",
            SubFields = "*"
          };
          var origin_org_id = Guid.Empty;
          using (var rc = org_fc.Search(qf))
          {
            if (!rc.MoveNext())
              return false;
            origin_org_id = rc.Current.GetGlobalID();//For the relate
          }
    
          // set up the row handles
          var originHandle = new RowHandle(org_fc, origin_org_id);    // entity
          var destinationHandle = new RowHandle(rowToken);            // document
    
          // create the KnowledgeGraphRelationshipDescription
          var rd = new KnowledgeGraphRelationshipDescription(originHandle, destinationHandle);
    
          // if you have additional custom attributes for the "HasDocument" relationship
          //var customHasDocAtts = new Dictionary<string, object>();
          //customHasDocAtts.Add("custom_attrib", "Foo");
          //customHasDocAtts.Add("custom_attrib2", "Bar");
          //var rd = new KnowledgeGraphRelationshipDescription(originHandle, destinationHandle, customHasDocAtts);
    
          // create the relate record using the same edit operation
          edit_op.Create(doc_rel_tbl, rd);
    
          //Call execute to create all the entities and relationship rows _together_
          return edit_op.Execute();
        }
      });
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.5 or higher.
    See Also