private void CreateField(IDataset d, IFeatureClass f, string name, string alias) { // IF FIELD DOES NOT EXIST, RETURN, ELSE, CREATE IField field = new FieldClass(); IFieldEdit fe = (IFieldEdit)field; fe.Name_2 = name; fe.AliasName_2 = alias; fe.Type_2 = esriFieldType.esriFieldTypeString; fe.Length_2 = 20; Invoke(new MethodInvoker(delegate { UpdateLabel.Text = "Creating field " + field.Name + "\nfor " + d.Name.Split('.')[1] + "... "; })); f.AddField(field); }
Solved! Go to Solution.
Use IFeatureClass::FindField to check if a field exists. If it returns -1, the field isn't in the feature class.if (f.findfield(name) == -1) return;
Call the FindField method on the feature class' Fields collection. If it returns -1 then the field doesn't exist.
if (f.findfield(name) == -1) return;
Use IFeatureClass::FindField to check if a field exists. If it returns -1, the field isn't in the feature class.if (f.findfield(name) == -1) return;
Call the FindField method on the feature class' Fields collection. If it returns -1 then the field doesn't exist.