ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / Map Class / ChangeVersion(VersionBase,VersionBase) Method
VersionBase object you want to find and replace with toVersionBase.
VersionBase object you want to replace to.
Example

In This Topic
    ChangeVersion(VersionBase,VersionBase) Method
    In This Topic
    Change GeoDatabase version of layers and standalone tables of fromVersionBase. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public void ChangeVersion( 
       VersionBase fromVersionBase,
       VersionBase toVersionBase
    )
    Public Sub ChangeVersion( _
       ByVal fromVersionBase As VersionBase, _
       ByVal toVersionBase As VersionBase _
    ) 

    Parameters

    fromVersionBase
    VersionBase object you want to find and replace with toVersionBase.
    toVersionBase
    VersionBase object you want to replace to.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    This operation is not supported on a map with pending edits.
    Example
    Switching between versions
    public void ChangeVersions(Geodatabase geodatabase, string toVersionName)
    {
      using (VersionManager versionManager = geodatabase.GetVersionManager())
      {
       VersionBaseType versionBaseType = versionManager.GetCurrentVersionBaseType();
    
       if (versionBaseType == VersionBaseType.Version)
       {
         Version fromVersion = versionManager.GetCurrentVersion();
         Version toVersion = versionManager.GetVersion(toVersionName);
         
         // Switch between versions
         MapView.Active.Map.ChangeVersion(fromVersion,toVersion);
       }
    
       if (versionBaseType == VersionBaseType.HistoricalVersion)
       {
         HistoricalVersion fromHistoricalVersion = versionManager.GetCurrentHistoricalVersion();
         HistoricalVersion toHistoricalVersion = versionManager.GetHistoricalVersion(toVersionName);
         
         // Switch between historical versions
         MapView.Active.Map.ChangeVersion(fromHistoricalVersion, toHistoricalVersion);
       }
    
       // Switch from HistoricalVersion to Version and vice-versa 
       // MapView.Active.Map.ChangeVersion(fromHistoricalVersion, toVersion);
       // MapView.Active.Map.ChangeVersion(fromVersion, toHistoricalVersion);
    
      }
    }
    Change Geodatabase Version of layers off a specified version in a map
    await QueuedTask.Run(() =>
    {
      //Getting the current version name from the first feature layer of the map
      FeatureLayer flyr = MapView.Active.Map.GetLayersAsFlattenedList()
              .OfType<FeatureLayer>().FirstOrDefault();  //first feature layer
      Datastore dataStore = flyr.GetFeatureClass().GetDatastore();  //getting datasource
      Geodatabase geodatabase = dataStore as Geodatabase; //casting to Geodatabase
      if (geodatabase == null)
        return;
    
      VersionManager versionManager = geodatabase.GetVersionManager();
      ArcGIS.Core.Data.Version currentVersion = versionManager.GetCurrentVersion();
    
      //Getting all available versions except the current one
      IEnumerable<ArcGIS.Core.Data.Version> versions = versionManager.GetVersions()
              .Where(v => !v.GetName().Equals(currentVersion.GetName(), StringComparison.CurrentCultureIgnoreCase));
    
      //Assuming there is at least one other version we pick the first one from the list
      ArcGIS.Core.Data.Version toVersion = versions.FirstOrDefault();
      if (toVersion != null)
      {
        //Changing version
        MapView.Active.Map.ChangeVersion(currentVersion, toVersion);
      }
    });
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also