OpenFileDialog dlg=new OpenFileDialog();
dlg.Filter="Shape file(*.shp)|*.shp";
dlg.Title="打开Shape数据文档";
dlg.Multiselect=true;
//定义存放打开IFeatureClass的字符串数组
string[] FilePath;
if(dlg.ShowDialog()==DialogResult.OK)
{
FilePath=new string[dlg.FileNames.Length];
FilePath=dlg.FileNames;
if(FilePath.Length > 0)
{
string WorkSpacePath =System.IO.Path.GetDirectoryName(FilePath[0]);
string[] ShapeFilePath=new string[FilePath.Length] ;
//获得打开IFeatureClass的字符串数组
for(int i=0;i<FilePath.Length;i++)
{
ShapeFilePath[i]=System.IO.Path.GetFileName(FilePath[i]);
}
IWorkspaceFactory pWorkspaceFactory=new ShapefileWorkspaceFactoryClass();
IWorkspace pWorkspace=pWorkspaceFactory.OpenFromFile(WorkSpacePath,0);
IFeatureWorkspace pFeatureWorkspace=pWorkspace as IFeatureWorkspace;
for(int i=0;i<ShapeFilePath.Length;i++)
{
IFeatureClass pFeatureClass=pFeatureWorkspace.OpenFeatureClass(ShapeFilePath[i]);
IDataset pDataset=pFeatureClass as IDataset;
IFeatureLayer pFeatureLayer=new FeatureLayerClass();
pFeatureLayer.FeatureClass=pFeatureClass;
pFeatureLayer.Name=pDataset.Name;
ILayer pLayer=pFeatureLayer as ILayer;
this.axMapControl2.Map.AddLayer(pLayer);
}
}
dlg.Filter="Shape file(*.shp)|*.shp";
dlg.Title="打开Shape数据文档";
dlg.Multiselect=true;
//定义存放打开IFeatureClass的字符串数组
string[] FilePath;
if(dlg.ShowDialog()==DialogResult.OK)
{
FilePath=new string[dlg.FileNames.Length];
FilePath=dlg.FileNames;
if(FilePath.Length > 0)
{
string WorkSpacePath =System.IO.Path.GetDirectoryName(FilePath[0]);
string[] ShapeFilePath=new string[FilePath.Length] ;
//获得打开IFeatureClass的字符串数组
for(int i=0;i<FilePath.Length;i++)
{
ShapeFilePath[i]=System.IO.Path.GetFileName(FilePath[i]);
}
IWorkspaceFactory pWorkspaceFactory=new ShapefileWorkspaceFactoryClass();
IWorkspace pWorkspace=pWorkspaceFactory.OpenFromFile(WorkSpacePath,0);
IFeatureWorkspace pFeatureWorkspace=pWorkspace as IFeatureWorkspace;
for(int i=0;i<ShapeFilePath.Length;i++)
{
IFeatureClass pFeatureClass=pFeatureWorkspace.OpenFeatureClass(ShapeFilePath[i]);
IDataset pDataset=pFeatureClass as IDataset;
IFeatureLayer pFeatureLayer=new FeatureLayerClass();
pFeatureLayer.FeatureClass=pFeatureClass;
pFeatureLayer.Name=pDataset.Name;
ILayer pLayer=pFeatureLayer as ILayer;
this.axMapControl2.Map.AddLayer(pLayer);
}
}