Hi ,
I'm trying to export a layer to a shape file programmatically in C#.
I found a VB code and translated and modified a bit as per my requirements. It fails at the last line.
pExportOp.ExportFeatureClass(pInDsName, null, pSelSet, null, pOutDatasetName, 1);
The compilation error is that it says cannot convert from IDatasetName to IfeatureClassName. Tried explicit casting but that also failed. Any help would be greatly appreciated.
Here is the code;
IActiveView activeView = clsFunctions.pMxDocument.ActiveView;
IMap map = activeView.FocusMap;
ILayer pLayer;
int intI = 0;
for (intI = 0; intI <= map.LayerCount - 1; intI++)
{
pLayer = map.get_Layer(intI);
if (pLayer.Name == cmbStreets.Text)
{
pFeatLayer_Compare = (IFeatureLayer)pLayer;
}
}
IFeatureClass pFc;
IFeatureClassName pINFeatureClassName;
IDataset pDataset;
IDatasetName pInDsName;
IFeatureSelection pFSel;
ISelectionSet pSelSet;
IFeatureClassName pFeatureClassName;
IDatasetName pOutDatasetName;
IWorkspaceName pWorkspaceName;
IExportOperation pExportOp;
pFc = pFeatLayer_Compare.FeatureClass;
pDataset = (IDataset)pFc;
pINFeatureClassName = (IFeatureClassName)pDataset.FullName;
pInDsName = (IDatasetName)pINFeatureClassName;
pFSel = (IFeatureSelection)pFeatLayer_Compare;
pSelSet = pFSel.SelectionSet;
//Define the output feature class name
pFeatureClassName = new FeatureClassName();
pOutDatasetName = (IDatasetName)pFeatureClassName;
pOutDatasetName.Name = "TestExport";
pWorkspaceName = new WorkspaceName();
pWorkspaceName.PathName = "c:\temp";
pWorkspaceName.WorkspaceFactoryProgID = "esriCore.shapefileworkspacefactory.1";
pOutDatasetName.WorkspaceName = pWorkspaceName;
pFeatureClassName.FeatureType = esriFeatureType.esriFTSimple;
//pFeatureClassName.ShapeType = esriGeometryAny;
pFeatureClassName.ShapeFieldName = "Shape";
//Export
pExportOp = new ExportOperation();
pExportOp.ExportFeatureClass(pInDsName, null, pSelSet, null, pOutDatasetName, 1);