I am coding an AddIn button to add a specific shapefile to my map. I borrowed from the code snippet finder but haven't had any luck using it. When I step through the project in debug mode, ArcMap always crashes on the line: IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(shapefile); Any help would be appreciated. public void AddShapefile()
{
IMxDocument mxd;
mxd = ArcMap.Application.Document as IMxDocument;
string shapeDir = "C:\\dev\\shapefiles";
string shapefile = "basins_today";
IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass();
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(shapeDir, 0); // Explicit Cast
IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(shapefile);
IFeatureLayer featureLayer = new FeatureLayerClass();
featureLayer.FeatureClass = featureClass;
featureLayer.Name = featureClass.AliasName;
featureLayer.Visible = true;
// Zoom to RFC extent
ESRI.ArcGIS.Geometry.IEnvelope pEnv = new ESRI.ArcGIS.Geometry.EnvelopeClass();
pEnv.PutCoords(-115.2, 34.89, -89.33, 51.92);
mxd.ActiveView.Extent = pEnv;
mxd.ActiveView.Refresh();
}