Select to view content in your preferred language

Automating the Change Version functionality in ArcMap

2629
10
12-23-2013 07:29 AM
RonAnkeny
Occasional Contributor
I'm trying to automatically change the version the user is connected to in ArcMap when a button is pushed but I'm having trouble finding the correct code interface. This is the first time I have had trouble finding the correct code and I am wondering if it is just not possible.

                _thisMap = _mHookHelper.FocusMap;
                IEnumLayer selLayers = _thisMap.get_Layers(pUID, true);
                ILayer aLayer = selLayers.Next();
                if (aLayer == null)
                {
                    throw new Exception("No Layers Present");
                }
                IFeatureLayer a_FLayer = (IFeatureLayer) aLayer;
                IFeatureClass a_FClass = a_FLayer.FeatureClass;
                ITable aTable = (ITable) a_FClass;
                IDataset aDS = (IDataset) aTable;
                _aWS = aDS.Workspace;
                IPropertySet pSet = _aWS.ConnectionProperties;
                object pProp = pSet.GetProperty("Version");
                string verName = pProp.ToString();
                if (!verName.Contains(editVersion))
                {
                 
                  CHANGE VERSION IN TOC HERE AUTOMATICALLY
     
                }
0 Kudos
10 Replies
SanajyJadhav
Deactivated User
You might want to look at this code.

You can call  ChangeVersion(pMxDoc, pOldWorkspace as IFeatureWorkspace, pVersion as IFeatureWorkspace); method after the line //update the layers in the mxdoc in my earlier post. This is the same method name, so you can change the old method name to something like "ChangeVersionByName".

public void ChangeVersionByName(IMxDocument MxDoc, IFeatureWorkspace OldWorkspace, string versionName)
        {
            try
            {
              //blah blah....

                //update the layers in the mxdoc         
                       ChangeVersion(pMxDoc, pOldWorkspace as IFeatureWorkspace, pVersion as IFeatureWorkspace);
            }
            catch (Exception ex)
            {
            }
        }

This new "ChangeVersion" method will start to update your map, tables, relationships making them point to the new version .

hope this helps.

S.
0 Kudos