Hi Alan,
Thank you very much for your help ,I can open my workspace using the absolute path.Now I have anthor problem,below is my code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.NetworkAnalyst;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.DataSourcesGDB;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private INAContext m_NAContext;
public Form1()
{
InitializeComponent();
Initialize();
}
private void Initialize()
{
IFeatureWorkspace featureWorkspace;
INetworkDataset networkDataset;
// Open GDB and NDS
//featureWorkspace = OpenWorkspace(@"C:\Program Files\ArcGIS\DeveloperKit\SamplesNET\data\SanFranciscoNetwork") as IFeatureWorkspace;
featureWorkspace = OpenWorkspace(@"E:\wlmq\test.mdb") as IFeatureWorkspace;
networkDataset = OpenNetworkDataset(featureWorkspace as IWorkspace, "test_ND");
//networkDataset = OpenNetworkDataset(featureWorkspace as IWorkspace, "Streets_nd");
//Create Layer for Network Dataset and add to ArcMap
ILayer layer;
INetworkLayer networkLayer;
networkLayer = new NetworkLayerClass();
networkLayer.NetworkDataset = networkDataset;
layer = networkLayer as ILayer;
layer.Name = "Network Dataset";
axMapControl1.AddLayer(layer, 0);
}
public IWorkspace OpenWorkspace(string strGDBName)
{
IWorkspaceFactory workspaceFactory;
//workspaceFactory = new ShapefileWorkspaceFactory();
workspaceFactory = new AccessWorkspaceFactory();
return workspaceFactory.OpenFromFile(strGDBName, 0);
}
public INetworkDataset OpenNetworkDataset(IWorkspace workspace, string strNDSName)
{
IWorkspaceExtensionManager workspaceExtensionManager;
IWorkspaceExtension workspaceExtension;
IDatasetContainer2 datasetContainer2;
// Get Workspace Extension
workspaceExtensionManager = workspace as IWorkspaceExtensionManager;
int count = workspaceExtensionManager.ExtensionCount;
for (int i = 0; i < count; i++)
{
workspaceExtension = workspaceExtensionManager.get_Extension(i);
if (workspaceExtension.Name.Equals("Network Dataset"))
{
datasetContainer2 = workspaceExtension as IDatasetContainer2;
try
{
return datasetContainer2.get_DatasetByName(esriDatasetType.esriDTNetworkDataset, strNDSName) as INetworkDataset;
}
catch
{
}
}
}
return null;
}
}
}
Now , I can run my project and no error.But I canâ??t see my networkDataset's geography in axMapControl1.So I try to change my workspace path and my networkDataset to "featureWorkspace = OpenWorkspace(@"C:\Program Files\ArcGIS\DeveloperKit\SamplesNET\data\SanFranciscoNetwork") as IFeatureWorkspace;" and
"networkDataset = OpenNetworkDataset(featureWorkspace as IWorkspace, "Streets_nd");",the result display the geography.Why can't my networkDataset diaplay normally?
Please tell me why ,Thank you!
Shirly