Select to view content in your preferred language

Automating the Change Version functionality in ArcMap

2624
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
JoshuaChisholm
Frequent Contributor
Good day Ron,

Are you trying to change the software level (ArcView\ArcEditor\ArcInfo)?

If so, you can change this in the given user's Environmental Variables. This can be edited with one of the following windows command prompt code lines:
SETX ESRI_SOFTWARE_CLASS "Viewer"
SETX ESRI_SOFTWARE_CLASS "Editor"
SETX ESRI_SOFTWARE_CLASS "Professional"

ArcView - "Viewer"
ArcEditor - "Editor"
ArcInfo- "Professional"

You should be able to access command line from .NET pretty easily. You may be able to find more info on changing software levels here.
0 Kudos
RonAnkeny
Occasional Contributor
Sorry for the confusion.

I am looking for a way to change the version of our SDE Geodatabase that the map is currently pointed at, e.g. from SDE.Default to editor.Editversion.

Just like can be done manually by right clicking the version in Source tab of the TOC and selecting change version.
0 Kudos
LeoDonahue
Deactivated User
Did you look at the VersionedWorkspace class?  It looks like it might do the job, but then there are also samples of this online that set properties of your connection to SDE.

http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/0001/0001000003s8000000.htm
0 Kudos
SanajyJadhav
Deactivated User
Try following code :

    public void ChangeVersion(IMxDocument MxDoc, IFeatureWorkspace OldWorkspace, string versionName)
        {
            try
            {
                //validation
                if ((pMxDoc == null) || (pOldWorkspace == null) || (String.IsNullOrEmpty(versionName) == true))
                {                    
                    return;
                }

                if (!(pOldWorkspace is IVersionedWorkspace))
                {
                    return;
                }

                IVersionedWorkspace pVersionedWorkspace;
                IVersion pVersion;

                pVersionedWorkspace = pOldWorkspace as IVersionedWorkspace;
                pVersion = pVersionedWorkspace.FindVersion(versionName);

                if (pVersion == null)
                {                  
                    return;
                }

                //update the layers in the mxdoc                
            }
            catch (Exception ex)
            {
            }
        }


HTH.
0 Kudos
RonAnkeny
Occasional Contributor
Try following code :

    public void ChangeVersion(IMxDocument MxDoc, IFeatureWorkspace OldWorkspace, string versionName)
        {
            try
            {
                //validation
                if ((pMxDoc == null) || (pOldWorkspace == null) || (String.IsNullOrEmpty(versionName) == true))
                {                    
                    return;
                }

                if (!(pOldWorkspace is IVersionedWorkspace))
                {
                    return;
                }

                IVersionedWorkspace pVersionedWorkspace;
                IVersion pVersion;

                pVersionedWorkspace = pOldWorkspace as IVersionedWorkspace;
                pVersion = pVersionedWorkspace.FindVersion(versionName);

                if (pVersion == null)
                {                  
                    return;
                }

                //update the layers in the mxdoc                
            }
            catch (Exception ex)
            {
            }
        }




Thanks for the suggestions Sanajy and Leo. I have no trouble getting the version I am trying to switch to (using IVersionedWorkspace), the problem I have is trying to get arcmap to reflect that version instead of the current one. I see no setters in any of the interfaces I have looked at for telling the currently viewed map to change the version it is looking at.

So I guess what I'm saying is, in Sanajy's code I'm having trouble with the line

//update layers in the mxdoc

Any further suggestions would be welcome.
0 Kudos
LeoDonahue
Deactivated User
you are so close.

UpdateContents
0 Kudos
RonAnkeny
Occasional Contributor
Alright. Perhaps I'm missing something, but I don't see an assignment of the new version to the current map prior to updating.



pVersionedWorkspace = pOldWorkspace as IVersionedWorkspace; <-- convert your current workspace to a versioned workspace
pVersion = pVersionedWorkspace.FindVersion(versionName); <-- get a hold of a specific version called versionName

??assign the current map to use pVersion??

Run Update Contents


Updating the contents without the missing link above only refreshes the current version, not the map with the new version. How do you assign the pVersion to the current document?
0 Kudos
LeoDonahue
Deactivated User
0 Kudos
by Anonymous User
Not applicable
How do you assign the pVersion to the current document?


IChangeDatabaseVersion Interface
0 Kudos