Select to view content in your preferred language

How to register as versioned using ArcGIS Pro SDK .NET?

925
8
Jump to solution
04-10-2023 02:04 PM
gisx
by
New Contributor II

Hi,

How to register a feature dataset as versioned using ArcGIS Pro SDK .NET?

The following is ArcObject codes:

ESRI.ArcGIS.Geodatabase.IVersionedObject pVersionedObject = null;
pVersionedObject = (ESRI.ArcGIS.Geodatabase.IVersionedObject)pFeatureDataset;
if (!pVersionedObject.IsRegisteredAsVersioned)
{
pVersionedObject.RegisterAsVersioned(true);
}

 

Thanks!

 

Tags (1)
0 Kudos
2 Solutions

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

You can do it by calling geoprocessing:

var mva = Geoprocessing.MakeValueArray(datasetName, "EDITS_TO_BASE");
await Geoprocessing.ExecuteToolAsync("RegisterAsVersioned_management", mva);‍‍

View solution in original post

gisx
by
New Contributor II

@GKmieliauskas @JinZ 

The RegisterAsVersion GP can only take input FeatureDataset as string.  So the input FeatureDataset object won't work even in the MakeValueArray method. 

With GDB connection on the fly, this will do the trick:

DatabaseConnectionProperties connectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.Oracle)
{
...
}
using (Geodatabase geodatabase = new Geodatabase(connectionProperties))
{
      // Open a FeatureDataset.
      using (FeatureDataset featureDataset = geodatabase.OpenDataset<FeatureDataset>("your_dataset_name"))
      {
		string path = featureDataset.GetPath().ToString().Replace("file:///", "");
		var mva = Geoprocessing.MakeValueArray(path, "NO_EDITS_TO_BASE");
		var gpResult = Geoprocessing.ExecuteToolAsync("management.RegisterAsVersioned", mva);
		Geoprocessing.ShowMessageBox(gpResult.Result.Messages, "GP Messages", gpResult.Result.IsFailed ? GPMessageBoxStyle.Error : GPMessageBoxStyle.Default);
      }
}

View solution in original post

8 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

You can do it by calling geoprocessing:

var mva = Geoprocessing.MakeValueArray(datasetName, "EDITS_TO_BASE");
await Geoprocessing.ExecuteToolAsync("RegisterAsVersioned_management", mva);‍‍
gisx
by
New Contributor II

Thanks @GKmieliauskas !!

0 Kudos
gisx
by
New Contributor II

Hi @GKmieliauskas ,

Is there any other way not using Geoprocessing call?

I am using enterprise geodatabase.  If I use Geoprocessing, I have to hardcode the input Feature Dataset's path using sde connection file. I try to avoid that. 

Can this be done inside of geodatabase connection? Thanks!

 

DatabaseConnectionProperties connectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.Oracle)
{
...
}
using (Geodatabase geodatabase = new Geodatabase(connectionProperties))
{
// register feature dataset as versioned
}

 

0 Kudos
GKmieliauskas
Esri Regular Contributor

I don't know another way.

Geoprocessing tool documentation here:

https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/register-as-versioned.htm 

It says that parameter must be Feature Dataset or Table View. There is no matter for Geoprocessing.MakeValueArray if you pass text string or FeatureDataset object. So code could look like this:

DatabaseConnectionProperties connectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.Oracle)
{
...
}
using (Geodatabase geodatabase = new Geodatabase(connectionProperties))
{
      // Open a FeatureDataset.
      using (FeatureDataset featureDataset = geodatabase.OpenDataset<FeatureDataset>("your_dataset_name"))
      {
           // register feature dataset as versioned
           var mva = Geoprocessing.MakeValueArray(featureDataset, "EDITS_TO_BASE");
           await Geoprocessing.ExecuteToolAsync("RegisterAsVersioned_management", mva);
      }
}

 

gisx
by
New Contributor II

Great! Let me try! Thanks for quick response!

0 Kudos
JinZ
by
New Contributor II

Does it work for you? It's not working for me

 

0 Kudos
gisx
by
New Contributor II

@GKmieliauskas @JinZ 

The RegisterAsVersion GP can only take input FeatureDataset as string.  So the input FeatureDataset object won't work even in the MakeValueArray method. 

With GDB connection on the fly, this will do the trick:

DatabaseConnectionProperties connectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.Oracle)
{
...
}
using (Geodatabase geodatabase = new Geodatabase(connectionProperties))
{
      // Open a FeatureDataset.
      using (FeatureDataset featureDataset = geodatabase.OpenDataset<FeatureDataset>("your_dataset_name"))
      {
		string path = featureDataset.GetPath().ToString().Replace("file:///", "");
		var mva = Geoprocessing.MakeValueArray(path, "NO_EDITS_TO_BASE");
		var gpResult = Geoprocessing.ExecuteToolAsync("management.RegisterAsVersioned", mva);
		Geoprocessing.ShowMessageBox(gpResult.Result.Messages, "GP Messages", gpResult.Result.IsFailed ? GPMessageBoxStyle.Error : GPMessageBoxStyle.Default);
      }
}
JinZ
by
New Contributor II

this works, Thanks!