AnsweredAssumed Answered

How can I modify a Layer File's data source using ArcObjects?

Question asked by jvickrey79 on Mar 26, 2012
Latest reply on Mar 27, 2012 by jvickrey79
Greetings,

I'm building an Add-in that lets users change datasources of all MXD's and Layer files in a directory of their choice.  I have the MXD part working but I cannot figure out the Layer file part.  In my code below, I've gathered a list of Layer files in this directory but now I need to open each layer file and change the data source information.  Can anyone shed some light on this?  Many thanks

//Now Loop through LYR Files if there are any and Process them..              for (int y = 0; y < LYList.Count; y++)             {                  string test = LayerFileLocation + "\\" + LYList[y].ToString();                 ILayerFile l = new LayerFileClass();                 l.Open(LayerFileLocation + "\\" + LYList[y].ToString());                  //I'm not sure what to do with a Layer file from here.  With an MXD I used the below code to loop through each layer and process it using IMapAdmin2.FireChangeFeatureclass()               }


Here is what I did for MXD's..
UID pUID = new UIDClass();                 pDoc.Open(MXDLocation + "\\" + AL[f].ToString());//+ fi.Name);                                  for (int i = 0; i < pDoc.MapCount; i++)                 {                     pMap = pDoc.get_Map(i);                      UID uid = new UIDClass();                     //uid.Value = "{EDAD6644-1810-11D1-86AE-0000F8751720}"; //  IGroupLayer                     uid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}"; //IFeatureLayer                     IEnumLayer layers = pMap.get_Layers(uid, true);       //Returns all layers including layers in grouplayers                     layers.Reset();                      pFeatureLayer = layers.Next() as IFeatureLayer;                     while (pFeatureLayer != null)                     {...Etc..etc

Outcomes