这段代码有问题吗?可以生成解决方案,但是还是不能加载shp文件啊。报错显示
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void addShapeFile()
{
System.Windows.Forms.OpenFileDialog openFileDialog;
openFileDialog = new OpenFileDialog();
openFileDialog.Title = "打开图层文件";
openFileDialog.Filter = "map documents(*.shp)|*.shp";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
FileInfo fileInfo = new FileInfo(openFileDialog.FileName);
String path = fileInfo.Directory.ToString();
String fileName = fileInfo.Name.Substring(0, fileInfo.Name.IndexOf("."));
try
{
axMapControl1.AddShapeFile(path, fileName);
}
catch (Exception e)
{
MessageBox.Show("添加图层失败!!!" + e.ToString());
}
}
}
private void button1_Click(object sender, EventArgs e)
{
addShapeFile();
}