Hi All -
I'm building an Add-in for ArcMap (using C# and ArcObjects) that provides a custom dialog with a textbox that expects a parcel APN number; entered by the user. If the APN is valid, zoom to the location. When I began developing this tool I took a subset of my Map Service parcel data and created a gdb.
I got everything working and assumed...(wrongly)... that I could simply change the CLSID reference in the code from working with geodatabase layers to MapServer sublayer. As I stated, this was wrong. It now appears that I have an invalid cast. Can anyone suggest how I might be able to save most of this code without having to rewrite it to work with a map service? The map service supports the Query operation, I suspect the answer lies within IQuery. On the positive side, I have created a tool that will successfully close ArcMap...rather quickly too I might add.
<Add-in code snippet>
IMxDocument pMxDoc = ArcMap.Document;
pMap = pMxDoc.FocusMap;
IEnumLayer pEnumLayer = null;
// string LayerCLSID = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
string LayerCLSID = "{B059B902-5C7A-4287-982E-EF0BC77C6AAB}"; // IMapServerSublayer
ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
uid.Value = LayerCLSID;
pEnumLayer = pMap.get_Layers(((ESRI.ArcGIS.esriSystem.UID)(uid)), true);
pEnumLayer.Reset();
ILayer layer = pEnumLayer.Next();
ILayer selLayer = null;
while (!(layer == null))
{
if (layer.Name == "Riverside Parcels")
{
selLayer = layer;
string sqlStatement = "APN = '" + textBox1.Text + "'";
IFeatureSelection fSelection = selLayer as IFeatureSelection; // <= **** Invalid Cast? ****
IQueryFilter qFilter = new QueryFilterClass();
esriSelectionResultEnum selectionResult = new esriSelectionResultEnum();
qFilter.WhereClause = sqlStatement;
fSelection.SelectFeatures(qFilter,selectionResult,false);
}//closes if
layer = pEnumLayer.Next();
}//closes while
Thanks
Tom