I have a MXD file where all layers point to an Oracle Spatial database. Recently our DBA changed the schema name. So now my MXD file has broken links, each time I open it, all my layers have a exclamation mark beside them.
In order to bulk change the new schema name in the MXD file, I've written an .NET ArcObjects application. But since all my layer data links are broken in my MXD, I do not have the capability to get a reference on IFeatureClass from a IFeatureLayer.
I've found on the web that is normal if a IFeatureLayer is broken within the MXD that the IFeatureClass always returns null.
Actually, all MXD's layers point on the schema "A" and now I want them to point on schema "B". How to do that programmatically?
Can you help me to get the good object that should give me access to change the QueryDef of my layers? Here is the code that I've written until now:
//Exit if no map document is selected
string sFilePath = openFileDialog1.FileName;
if (sFilePath == "") return;
IMapDocument ipMapDoc;
ipMapDoc = new MapDocumentClass();
ipMapDoc.Open(sFilePath);
IMap map = ipMapDoc.get_Map(0);
IEnumLayer layers = map.get_Layers();
ILayer layer;
while ((layer = layers.Next()) != null)
{
if (layer is IFeatureLayer)
{
IFeatureLayer featureLayer = layer as IFeatureLayer;
IFeatureClass featureClass = featureLayer as IFeatureClass;
if (featureClass == null)
{
Console.WriteLine("FeatureClass where FeatureLayer name is " + layer.Name + " is null");
}
}
}