[C#] Open Network Dataset

1906
1
Jump to solution
03-26-2012 03:48 AM
Highlighted
New Contributor II
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         }
0 Kudos
1 Solution

Accepted Solutions
Highlighted
New Contributor II
Problem is "solved". Seems like I faced a bug: there were some russian symbols in feature class (source for network) name.

I created same dataset and source featureclass with only english letters in name, then created network dataset. My code works fine with this network dataset.

View solution in original post

0 Kudos
1 Reply
Highlighted
New Contributor II
Problem is "solved". Seems like I faced a bug: there were some russian symbols in feature class (source for network) name.

I created same dataset and source featureclass with only english letters in name, then created network dataset. My code works fine with this network dataset.

View solution in original post

0 Kudos