ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data.DDL Namespace / SchemaBuilder Class / CreateFileKnowledgeGraph Method
Represents the physical path to create the file ArcGIS.Core.Data.Knowledge.KnowledgeGraph.
Example

In This Topic
    CreateFileKnowledgeGraph Method
    In This Topic
    Creates a new file ArcGIS.Core.Data.Knowledge.KnowledgeGraph at the specified path.
    Syntax
    Public Shared Function CreateFileKnowledgeGraph( _
       ByVal kgConnectionPath As KnowledgeGraphConnectionProperties _
    ) As KnowledgeGraph
    public static KnowledgeGraph CreateFileKnowledgeGraph( 
       KnowledgeGraphConnectionProperties kgConnectionPath
    )

    Parameters

    kgConnectionPath
    Represents the physical path to create the file ArcGIS.Core.Data.Knowledge.KnowledgeGraph.

    Return Value

    Exceptions
    ExceptionDescription

    The path contains an invalid Windows folder character or the file knowledge graph name is invalid.

    -or-

    The length of the local path is greater than 215 characters.

    kgConnectionPath is null.
    This method can only be used with a local path.
    The name of the file ArcGIS.Core.Data.Knowledge.KnowledgeGraph contains a colon.
    The file ArcGIS.Core.Data.Knowledge.KnowledgeGraph already exists.
    A geodatabase-related exception has occurred.
    Remarks
    Use this method to create a local file-based knowledge graph only. Attempting to create a knowledge graph using a Url will result in an exception. The folder specified in the kgConnectionPath input param must already exist.
    Example
    Create a File Knowledge Graph with SchemaBuilder
    {
            await QueuedTask.Run(() =>
    {
      //Starting at 3.7, users can use _file_ knowledge graphs
      //The extension for a file kg is ".knowledgegraph"
      string kgPath = @"C:\Data\KG\Filebased_KG";
      string kgFileName = @"Test_File_KG.knowledgegraph";
    
      //The file knowledge graph must NOT already exist or a GeodatabaseWorkspaceException
      //exception will be thrown
      string finalFileName = string.Empty;
      // ensure new file name is unique
      string baseFileName = System.IO.Path.GetFileNameWithoutExtension(kgFileName);
      int extraCount = 0;
      string extraFileName = string.Empty;
      string fullPath = string.Empty;
      do
      {
        fullPath = System.IO.Path.Combine(
                    kgPath, baseFileName + extraFileName + ".knowledgegraph");
        ++extraCount;
        extraFileName = $"({extraCount})";
      }
      while (System.IO.File.Exists(fullPath));
    
      System.Diagnostics.Debug.WriteLine($"Creating {System.IO.Path.GetFileName(fullPath)}");
    
      var kgConnProps = new KnowledgeGraphConnectionProperties(
                                                      new Uri(fullPath));
      try
      {
        using (var kg = SchemaBuilder.CreateFileKnowledgeGraph(kgConnProps))
        {
          //TODO - use the new KG
    
        }
      }
      catch (Exception ex)
      {
        System.Diagnostics.Debug.WriteLine(ex.ToString());
      }
    });
          }
    Requirements

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

    ArcGIS Pro version: 3.7 or higher.
    See Also