AnsweredAssumed Answered

[C#] Open Network Dataset

Question asked by harrisonford on Mar 26, 2012
Latest reply on Mar 27, 2012 by harrisonford
Hi,

I use this code to open Network Dataset, but it fails with HRESULT on datasetContainer3.get_DatasetByName().

        public static ESRI.ArcGIS.Geodatabase.INetworkDataset OpenNetworkDataset1(ESRI.ArcGIS.Geodatabase.IWorkspace networkDatasetWorkspace, System.String networkDatasetName, System.String featureDatasetName)         {             if (networkDatasetWorkspace == null || networkDatasetName == "" || featureDatasetName == null)             {                 return null;             }              ESRI.ArcGIS.Geodatabase.IDatasetContainer3 datasetContainer3 = null;             switch (networkDatasetWorkspace.Type)             {                 case ESRI.ArcGIS.Geodatabase.esriWorkspaceType.esriFileSystemWorkspace:                      // Shapefile or SDC network dataset workspace                     ESRI.ArcGIS.Geodatabase.IWorkspaceExtensionManager workspaceExtensionManager = networkDatasetWorkspace as ESRI.ArcGIS.Geodatabase.IWorkspaceExtensionManager; // Dynamic Cast                     ESRI.ArcGIS.esriSystem.UID networkID = new ESRI.ArcGIS.esriSystem.UIDClass();                      networkID.Value = "esriGeoDatabase.NetworkDatasetWorkspaceExtension";                     ESRI.ArcGIS.Geodatabase.IWorkspaceExtension workspaceExtension = workspaceExtensionManager.FindExtension(networkID);                     datasetContainer3 = workspaceExtension as ESRI.ArcGIS.Geodatabase.IDatasetContainer3; // Dynamic Cast                     break;                  case ESRI.ArcGIS.Geodatabase.esriWorkspaceType.esriLocalDatabaseWorkspace:                  // Personal Geodatabase or File Geodatabase network dataset workspace                  case ESRI.ArcGIS.Geodatabase.esriWorkspaceType.esriRemoteDatabaseWorkspace:                      // SDE Geodatabase network dataset workspace                     ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = networkDatasetWorkspace as ESRI.ArcGIS.Geodatabase.IFeatureWorkspace; // Dynamic Cast                     ESRI.ArcGIS.Geodatabase.IFeatureDataset featureDataset = featureWorkspace.OpenFeatureDataset(featureDatasetName);                     ESRI.ArcGIS.Geodatabase.IFeatureDatasetExtensionContainer featureDatasetExtensionContainer = featureDataset as ESRI.ArcGIS.Geodatabase.IFeatureDatasetExtensionContainer; // Dynamic Cast                     ESRI.ArcGIS.Geodatabase.IFeatureDatasetExtension featureDatasetExtension = featureDatasetExtensionContainer.FindExtension(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTNetworkDataset);                     datasetContainer3 = featureDatasetExtension as ESRI.ArcGIS.Geodatabase.IDatasetContainer3; // Dynamic Cast                     break;             }              if (datasetContainer3 == null)                 return null;              ESRI.ArcGIS.Geodatabase.IDataset dataset = datasetContainer3.get_DatasetByName(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTNetworkDataset, networkDatasetName);              return dataset as ESRI.ArcGIS.Geodatabase.INetworkDataset; // Dynamic Cast         }

Outcomes