psukardi

Edit a ShapeFile with ArcObjects Programatically

Discussion created by psukardi on Mar 8, 2011
Latest reply on Mar 9, 2011 by agray1
I currently have a basic shapefile that I want to edit in ArcObjects in C#.

I've created a shape file by creating a FeatureClass , Workspace and then obviously passing in my shape.  In this case it's just a simple Polyline with a few points on it.  What I'd like to do is have the ability to update this shapefile.

I'm assuming I need to re-use that FeatureClass, Workspace and pass in a new shape.  However, what I'm doing doesn't seem to work.  This is where I'm at on the edit - any advice would be great.

IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)inWorkspace;
workspaceEdit.StartEditing(true);
workspaceEdit.StartEditOperation();

ComReleaser comReleaser = new ComReleaser();

IFeatureCursor featureCursor = inFeatureClass.Update(null , true);

IFeature feature = null;
while((feature = featureCursor.NextFeature()) != null)
{
   int id = feature.Fields.FindField("shape");
   IFeatureBuffer featureBuffer = inFeatureClass.CreateFeatureBuffer();
   featureCursor.DeleteFeature(); //Delete the old
   featureBuffer.Shape = (IGeometry)inShape;
   featureCursor.InsertFeature(featureBuffer);
}

workspaceEdit.StopEdidtOperation();
workspaceEdit.StopEditing(true);

Outcomes