AnsweredAssumed Answered

Equivalent to Arcpy's updateConnectionProperties

Question asked by TomGeo on Sep 15, 2020
Latest reply on Sep 22, 2020 by TomGeo

I have a couple of map panes in ArcGIS Pro where the data source might differ from one occasion to te other. However, the name of the FeatureLayers are constant.

I am trying to adjust the underlaying data source based on user input. Meaning, the user has an OpenItemDialog listening on geodatabases. Plan is to use the retrieved path for the update.

However, I don't succeed. 

 

In the following code snippet the selectedMapAjour is of type Map

 

if (selectedMapAjour != null && !string.IsNullOrEmpty(PathGdbAjour))
{
    foreach (FeatureLayer layer in selectedMapAjour.Layers.OfType<FeatureLayer>())
    {
        GetSetDataConnection(layer, PathGdbAjour);
    }
}

private async void GetSetDataConnection(FeatureLayer layer, string newGDB)
{
    await QueuedTask.Run(() =>
    {
        CIMFeatureLayer def = layer.GetDefinition() as CIMFeatureLayer;
        var dcon = def.FeatureTable.DataConnection as CIMStandardDataConnection;
        dcon.WorkspaceConnectionString = System.IO.Path.Combine(newGDB, layer.Name);
        layer.SetDefinition(def);
    });
}

 

The code runs through... only the exclamation mark in the TOC of the map do not disappear. Although, the path set via dcon.WorkspaceConnectionString is reflected in the properties of the FeatureLayers in the TOC.

Hence, I am not sure if my attempt to alter the data source worked and I am missing some refresh or update call, or if this does not work at all.

 

I basically need a C# equivalent of updateConnectionProperties.

Thereafter, I will have to adjust the symbology, so ApplySymbologyFromLayer would be next. 

 

Does anybody has an example for this stuff?

 

Best Thomas

Outcomes