hawkinsma

Possible to edit a version programmatically?

Discussion created by hawkinsma on Dec 13, 2013
Latest reply on Dec 17, 2013 by hawkinsma
Does anyone know if it is possible to edit a version programmatically? Below is some sample code where I locate a users version and attempt to create a new feature in it. It works without any errors but the new features always end up in the default version. I've also tried opening the workspace from a sde connection file that is set to a specific version but the result is the same.. changes are applied to the default version.

The only place I find mention of this is in a thread from EDN 9.2 and prior where it describes versions as database states and says that it isn't possible to edit the versions directly and talks about editing states, etc.

http://edndoc.esri.com/arcsde/9.1/java_api/overview/editing_versions.htm

            IWorkspaceFactory2 WrkSpcFact = new SdeWorkspaceFactoryClass();
            
            IWorkspace WrkSpc;
     WrkSpc = WrkSpcFact.OpenFromFile("\\MyConnection.sde", 0);
  
            IVersionedWorkspace3 VrsWrkSpc;
            VrsWrkSpc = WrkSpc as IVersionedWorkspace3;

     //get version for current system user
            IEnumVersionInfo VerEnum = VrsWrkSpc.Versions;
            IVersionInfo VersInfo = VerEnum.Next();
            string UserID = Environment.UserName.ToUpper();
            string VersionName;
            string TargetVersionName = "";
            IVersion TargetVersion = null;
            while (VersInfo != null)
            {
                VersionName = VersInfo.VersionName;
                VersionName = VersionName.ToUpper();
                if (VersionName.Contains(UserID))
                {
                    TargetVersionName = VersInfo.VersionName;
                    TargetVersion = VrsWrkSpc.FindVersion(VersInfo.VersionName);       
                }
                VersInfo = VerEnum.Next();
            }
            

     //create workspace from version
     IFeatureWorkspace FeatWrkSpc;
     FeatWrkSpc = (IFeatureWorkspace)TargetVersion;
            IFeatureClass SitePlanFeatClass = FeatWrkSpc.OpenFeatureClass("BASE_ADMIN.site_plan");

            //start SDE versioned editing session
            IWorkspaceEdit VrsWrkSpcEdit = (IWorkspaceEdit)FeatWrkSpc;
            IMultiuserWorkspaceEdit MUVrsWrkSpcEdit = (IMultiuserWorkspaceEdit)VrsWrkSpcEdit;
            
     MUVrsWrkSpcEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned);
            VrsWrkSpcEdit.StartEditOperation();

            IFeature NewSitePlanFeature = SitePlanFeatClass.CreateFeature();
            NewSitePlanFeature.Shape = NewPolygonFeat.ShapeCopy;

            //populate some fields, etc

            //save
            NewSitePlanFeature.Store();

            VrsWrkSpcEdit.StopEditOperation();
            VrsWrkSpcEdit.StopEditing(true);

Outcomes