Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm creating an Add-in for ArcCatalog using C# that modifies the datasources of layers in a MXD and .LYR files by themselves. I have gotten the MXD code to work but I'm lost with how to modify a .LYR file without the use of IMap. Does anyone have any code suggestions?

To load an MXD and loop and start modifying layers in the TOC was simply something like:

UID pUID = new UIDClass();


            for (int i = 0; i < pDoc.MapCount; i++)
                pMap = pDoc.get_Map(i);

                UID uid = new UIDClass();
                uid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}"; //IFeatureLayer
                IEnumLayer layers = pMap.get_Layers(uid, true);       //Returns all layers

But I'm unsure how to get this process going for standalone .LYR files..

ILayerFile l = new LayerFileClass();
share|improve this question
Neil Clemmons offered some great insight on how to do this using ArcObjects. Here is the link in case anyone is interested.… – DaBears Mar 27 '12 at 14:25
up vote 0 down vote accepted

Do you just need to do "l.Layer"? Hard to say since not sure what\how you do the processing after "IEnumLayer layers = pMap.get_Layers(uid, true);".

One point to note is the .lyr file's Layer could be a group layer so you would need to check and gets its contents (and ensure its not a grouplayer in grouplayer ...), basically some sort of recursive function.

Have said the above, depending upon what version you are on you might look at arcpy.

gis.stackexchange ....change-data-source-path-in-lyr-files-in-arcgis-10

share|improve this answer
Hi dark fader- I was hoping to do this in C# using ArcObjects but I guess I will just make a seperate Add-in using arcpy as you suggested. – DaBears Mar 26 '12 at 12:29
Unless you are using the 10.1 beta you cannot create add-ins using arcpy. Maybe you meant a script tool? – blah238 Mar 28 '12 at 0:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.