3

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
pEnumLayer.Reset();
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?

asked May 8, 2015 at 18:02
1
  • 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. Commented May 8, 2015 at 19:10

2 Answers 2

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.

answered May 9, 2015 at 9:45
1

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

answered May 9, 2015 at 8:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.