ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data.Knowledge Namespace / KnowledgeGraphConnectionProperties Class / PathOrURL Property
Example

In This Topic
    PathOrURL Property
    In This Topic
    Gets the path or service URL.
    Syntax
    Public ReadOnly Property PathOrURL As Uri
    public Uri PathOrURL {get;}
    Example
    Opening a Connection to a File KnowledgeGraph
    {
      await QueuedTask.Run(() =>
      {
        //Starting at 3.7, users can connect to a _file_ knowledge graph
        //The extension for a file kg is ".knowledgegraph"
        // Any path you want
        string kgPath = @"C:\Data\KG\Filebased_KG";
        string kgFileName = @"Test_File_KG.knowledgegraph";
    
        var kg_full_path = System.IO.Path.Combine(kgPath, kgFileName);
    
        var kg_props = new KnowledgeGraphConnectionProperties(new Uri(kg_full_path));
        try
        {
          //Open a connection
          using (var kg = new KnowledgeGraph(kg_props))
          {
            //TODO...use the File KnowledgeGraph
            var i = 0;
            //Get the featureclass definitions from the KG datastore
            var fc_defs = kg.GetDefinitions<FeatureClassDefinition>();
            //For each feature class definition, get the corresponding
            //feature class. Note: The name of the feature class will match 
            //the name of its corresponding KnowledgeGraph named object type
            //in the KnowledgeGraph graph data model
            foreach (var fc_def in fc_defs)
            {
              var fc_name = fc_def.GetName();
              System.Diagnostics.Debug.WriteLine($"FeatureClass[{i++}] {fc_name}");
            }
          }
        }
        catch (GeodatabaseNotFoundOrOpenedException ex)
        {
          System.Diagnostics.Debug.WriteLine(ex.ToString());
        }
      });
    }
    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