日期:2014-05-18  浏览次数:21873 次

WorkSpaceFactory.OpenFromFile打开失败是为什么 异常
用WorkSpaceFactory.OpenFromFile打开失败是为什么,编译显示:异常来自 HRESULT:0x80040258
我检查了端点句(也就是OpenFromFile处)以前,值能传进去。
求高手解答



  private void button1_Click(object sender, EventArgs e)
  {
  System.Windows.Forms.OpenFileDialog openFileDialog;
  openFileDialog = new OpenFileDialog();
  openFileDialog.Title = "打开shp文件";
  openFileDialog.Filter = "shp layer(*.shp)|*.shp";
  if (openFileDialog.ShowDialog() == DialogResult.OK)
  {
  string file = openFileDialog.FileName;
  string filePath, fileName;
  int index = 0;
  index = file.LastIndexOf("\\");
  filePath = file.Substring(0,index);
  fileName = file.Substring(index+1,file.Length-index-1);
  IWorkspaceFactory workspaceFactory;
  IFeatureWorkspace featureWorkspace;
  IFeatureLayer featureLayer;
  IWorkspace workSpace;
  workspaceFactory = new ShapefileWorkspaceFactoryClass();
  workSpace = workspaceFactory.OpenFromFile(file,0); 
  featureWorkspace=workSpace as IFeatureWorkspace;
  featureLayer=new FeatureLayerClass();
  featureLayer.FeatureClass=featureWorkspace.OpenFeatureClass(fileName);
  featureLayer.Name=featureLayer.FeatureClass.AliasName;
  this.axMapControl1.AddLayer(featureLayer as ILayer);
  CreatePolyline();
  this.axMapControl1.Refresh();
  }
  }


------解决方案--------------------
你把workspaceFactory.OpenFromFile(file,0)里面的这个file参数改成文件所在的路径(不包括文件名)