using System;
using System.Text;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.esriSystem;
namespace EngineProj
{
class Program
{
[STAThread]
static void Main(string[] args)
{
string gdbName = @"C:\Projects\test\lines.shp";
IWorkspace workspace = null;
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
IAoInitialize ao = new AoInitializeClass();
ao.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcEditor);
Type factoryType = Type.GetTypeFromProgID("esriDataSourcesFile.ShapefileWorkspaceFactory");
IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
// This line fails with COMException: Exception from HRESULT: 0x80040228
workspace = workspaceFactory.OpenFromFile(gdbName, 0);
}
}
}using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.DataSourcesFile; IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass(); IWorkspace workspace = workspaceFactory.OpenFromFile(string_ShapefileDirectory, 0); IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace; IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(string_ShapefileName);
The workspace for a shapefile is the directory that contains the files that make up the shapefile. The problem with the code that you posted is that you're passing in the path to the *.shp file, which is incorrect. The workspace for a file geodatabase is also a directory. The workspace for a personal geodatabase is the database file. So, make sure you're passing in the correct path for the type of workspace you're trying to open. A recent thread also suggested that there is a bug when binding using the EngineOrDesktop option. If you have Engine installed but not licensed then the binding will fail even if you have Desktop installed and properly licensed.