2

I'm trying to add a field to a FeatureLayer, this is the code I'm using to do this:

IMxDocument mxd = (IMxDocument) app.getDocument();
FeatureLayer flayer = ((FeatureLayer)mxd.getSelectedLayer());
IField newField = null;
newField = new Field();
IFieldEdit newFieldEdit = (IFieldEdit) newField;
newFieldEdit.setAliasName("Id2");
newFieldEdit.setName("Id2");
newFieldEdit.setType(esriFieldType.esriFieldTypeString);
newFieldEdit.setLength(100);
flayer.addField(newFieldEdit);

However it raises an exception, according the documentation I should to get an ISchemaLock but I have no idea how to get a schemalock from a FeatureLayer, Does anyone have any idea?

user2005494
  • 189
  • 1
  • 12
  • 1
    `it raises an exception` --> What exception does it raise? – iRuth Feb 23 '15 at 04:26
  • AutomationException: 0x80004005 - Unspecified error, Actually I'm trying to add two fields, the first one is numeric, I can add it without problems, the error appears when trying to append the second field (string). – user2005494 Feb 23 '15 at 14:32
  • 1
    will this help? http://gis.stackexchange.com/questions/110586/adding-field-to-feature-class-using-arcobjects-and-c – vinayan Feb 27 '15 at 12:18
  • 2
    For a start, the featurelayer interface has no method called "addfield", this is a method on the featureclass interface, so your last line should be: flayer.featureclass.addField(newFieldEdit) – pvdev Mar 03 '15 at 12:23

0 Answers0