Find a text inside a feature class

893
2
10-24-2016 05:46 AM
DharmaRajan
Occasional Contributor

I want to retrieve the records having a text inside the feature class irrespective of field name using Arcobjects.

0 Kudos
2 Replies
JaredCaccamo
Esri Contributor

This would be how you verify the field type to be a text(string). Related samples are at the bottom. http://desktop.arcgis.com/en/arcobjects/latest/net/webframe.htm#IField_Type.htm

Best of luck,

Jared

0 Kudos
CarstenSchumann
Occasional Contributor

Simply loop all fields of all records from your table:

IEnumerable<IFeature> GetFeaturesBySearchValue(object searchValue)
{
    var featureClass = myWorkspace.OpenFeatureClass(fcName);
    var cursor = featureClass.Search(null, true);
    var fields = featureClass.Fields;
    IFeature feature;

    while((feature = cursor.NextFeature()) != null)
    {       
        for (int i = 0; i <= fields.FieldCount - 1; i++) 
        {
            var theValue = feature.get_Value(i);
            if (theValue == searchValue) yield return feature;
        }
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Be aware to also release the features and the cursor when you´re done with them.

0 Kudos