I'm currently working on a ArcObjects C# project that will repoint datasources for layers of various types. Basically a database is maintained that holds the old datasource connections and the new connections. When the user presses a button, the application goes through all the current layers in ArcDesktop and compares the layers current datasource with the new one. If there is a difference, it resets the datasource.

However, I'm not quite sure how to access the datasource, and in my perusings of this stackexchange, I noticed someone who was working on something similar, but they were using raster layers. I'm not too familiar with ArcGIS and didn't know if I needed to handle feature layers differently as he mentions he already found a solution for feature layers.

Here's the section I'm trying to change in ArcDesktop:enter image description here

I have everything working just fine except the changing of those datasources. I found this resource on arcgis, but it doesn't appear to change those strings, though I could be mistaken.

This is what I currently have:

//Loop through all layers and get their information
pLayer = pEnumLayer.Next();
while (pLayer != null)
            Log.Debug("Manipulating the layer: " + pLayer.Name);
            IDataLayer dataLayer = (IDataLayer)pLayer;
            var datasource = dataLayer.DataSourceName; // this is what I believe to be the current datasource

            Log.Debug("Repaired layer: " + pLayer.Name);
            pLayer = pEnumLayer.Next();

Is that the correct datasource I'm looking for? If so, would all I need to do to change the datasource is to set that variable to the new datasource string and then redraw the map?

  • I think you need to dig deeper to the featureLayer.FeatureClass level and then as the link you posted notes to use the IMapAdmin2.FireChangeFeatureClass Method.
    – artwork21
    Commented May 8, 2015 at 19:10

2 Answers 2


You should use IDataSourceHelperLayer Interface:

Code Snippet:

IDataSourceHelperLayer dsh = new DataSourceHelper() as IDataSourceHelperLayer;
dsh.ReplaceName(pLayer, newIName, false);

You can also use IDataSourceHelperLayer.FindAndReplaceWorkspaceNamePath method.


Esri's online help, there are examples of this problem, you can refer to this example.

URL: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//00490000002r000000

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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