I've been working on this for a little while now, and can not seem to get this thing working.
I've managed to export a geodatabase feature class and shapefile to a shapefile, but what I'm struggling with right now is writing an in-memory feature layer (one that is created based on a selection of features) to a shapefile/geodatabase.
If anyone can help me with a code snippet (doesn't matter the language), or some links to some dark corner of the ESRI docs, I would be much obliged.
UPDATE
I used the following code to create the IFeatureLayer:
IFeatureSelection featureSelection = (IFeatureSelection)layer;
if (featureSelection.SelectionSet.Count > 0)
{
IFeatureLayerDefinition2 featDef = (IFeatureLayerDefinition2)featureSelection;
IFeatureLayer fLayer = featDef.CreateSelectionLayer(
String.Format( CultureInfo.InvariantCulture,
"{0}_Selection", layer.Name ),
true, "", "" );
featureSelection.Clear();
if (fLayer != null)
{
_hook.FocusMap.AddLayer( fLayer );
_hook.ActiveView.Refresh();
}
}
This creates and adds a new layer to the TOC.
What I'm missing now is taking that Feature selection and saving this to a Shapefile (for now).
The code example I've been working with is from esri code snippets but I'm getting stuck on the following:
IDataset sourceDataset = (IDataset)_layer;
IWorkspace sourceWorkspace;
IPropertySet propertySet = sourceDataset.Workspace.ConnectionProperties;
sourceWorkspace = sourceDataset.Workspace.WorkspaceFactory.Open( propertySet, 0 );
if (sourceDataset.FullName != null)
{
// HERE - Invalid Cast Exception.
IWorkspaceName sourceWorkspaceName = (IWorkspaceName)sourceDataset.FullName;
}
The full exception is here:
Unable to cast COM object of type 'System.__ComObject' to interface type 'ESRI.ArcGIS.Geodatabase.IWorkspaceName'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{FADD975C-E36F-11D1-AA81-00C04FA33A15}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
I guess the exception is thrown because the FullName property though is not empty is not compatible because of the type of COM object it is wrapping.
Any thoughts?