In the 9.3 code you could just do a MapLayer.Layer to get the FeatureLayer. But in 10.1.1 they changed FeatureLayer to FeatureSource AND removed the Layer property from MapLayer.
Here's the old code someone else wrote that I'm upgrading:
static public MapLayer FindMapLayer(string sLayerName, Map theMap)
{
MapLayer lyr = null;
try
{
lyr = theMap.MapLayers[sLayerName];
}
catch { }
return lyr;
}
static public FeatureLayer FindFeatureLayer(string sLayerName, Map theMap)
{
FeatureLayer featLyr = null;
MapLayer lyr = FindMapLayer(sLayerName, theMap);
if (lyr != null)
{
featLyr = lyr.Layer;
}
return featLyr;
}
I figured it out. You have to look in the mobilecache.FeatureSources collection. The Name will match the same name you named the LAYER in your MXD (the exact string you see in the table of contents) that you published as a service in ArcGIS Server.
public static FeatureSource FindFeatureLayer(string featureSourceName, Map theMap)
{
//TODO: this may not work if the feature source name doesn't match the map layer name!
FeatureSource featSource = null;
//10.1.1
//Just grab the first map layer in order to get at the mobile cache and its
// collection of feature sources.
MobileCacheMapLayer cacheMapLayer = GetMobileCacheLayer(theMap);
if (cacheMapLayer != null)
{
featSource = cacheMapLayer.MobileCache.FeatureSources[featureSourceName];
}
return featSource;
}
public static MobileCacheMapLayer GetMobileCacheLayer(Map theMap)
{
foreach (var layer in theMap.MapLayers)
{
if(layer is MobileCacheMapLayer)
return (MobileCacheMapLayer)layer;
}
return null;
}