this.openFileDialog1.Filter = "图像数据(*.tif,*.jpg,*.bmp,*.gif)|*.tif;*.jpg;*.bmp;*.gif";
this.openFileDialog1.Title = "打开影像数据";
this.openFileDialog1.Multiselect = false;
string fileName = "";
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
fileName = this.openFileDialog1.FileName;
string filepath;
string file;
string file1;
int lastIndex;
lastIndex = fileName.LastIndexOf(@"");
filepath = fileName.Substring(0, lastIndex);
file = fileName.Substring(lastIndex + 1);
//导入SDE数据库
rasterWorkspaceEx = workspace as IRasterWorkspaceEx;
IWorkspaceFactory tifwpf = new RasterWorkspaceFactoryClass();
IWorkspace tifwp = tifwpf.OpenFromFile(filepath, 0);
IRasterWorkspace tifrwp = tifwp as IRasterWorkspace;
IRasterDataset rasterDataset = tifrwp.OpenRasterDataset(file);
lastIndex = file.LastIndexOf(@".");
file1 = file.Substring(0, lastIndex);
imortRasterData(filepath, file, file1);
MessageBox.Show("导入成功");
不知道怎么解决这个问题,感谢解答!!
你先试着把 filepath这个变量打印出来,看看是什么结果,根据报错感觉上是估计文件没有找到的问题
嗯,你把报错截图或者是复制出来发给我
已经解决了,谢谢!
解决的代码是把
string filepath;
string file;
string file1;
int lastIndex;
lastIndex = fileName.LastIndexOf(@"");
filepath = fileName.Substring(0, lastIndex);
file = fileName.Substring(lastIndex + 1);
改成了
FileInfo fileInfo = new FileInfo(fileName);
string filepath = fileInfo.DirectoryName;
string file = fileInfo.Name;