Using ArcObjects to retrieve all versions of ArcSDE in C#

Recently, I needed to get all the existing versions of an ArcGIS database (sde.DEFAULT, and so on). To do so, I decided to use ArcObjects in C#.NET. I found it pretty complicated to manage to get what I wanted to do, so I’m placing my code on this blog.

First, you need to connect to a valid license.

ESRI.ArcGIS.esriSystem.esriLicenseStatus eLicenseStatus = init.IsProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);

if (eLicenseStatus == ESRI.ArcGIS.esriSystem.esriLicenseStatus.esriLicenseAvailable)
{
init.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);
}

Then,  connect to the ArcSDE Service.

ESRI.ArcGIS.Geodatabase.IWorkspaceFactory pWFactory = new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactory();
ESRI.ArcGIS.Geodatabase.IWorkspace pWorkspace = null;

ESRI.ArcGIS.esriSystem.PropertySet propertySet = new ESRI.ArcGIS.esriSystem.PropertySetClass();
propertySet.SetProperty(“server”, m_ConnectionInformationData.ServerName);
propertySet.SetProperty(“database”, m_ConnectionInformationData.DatabaseName);
propertySet.SetProperty(“user”, m_ConnectionInformationData.UserName);
propertySet.SetProperty(“password”, m_ConnectionInformationData.UserPassword);
propertySet.SetProperty(“instance”, m_ConnectionInformationData.InstanceName);
propertySet.SetProperty(“version”, m_ConnectionInformationData.Version);

pWorkspace = pWFactory.Open(propertySet, 0);

Cast your workspace to a VersionedWorkspace:

ESRI.ArcGIS.Geodatabase.IVersionedWorkspace versionedWorkspace = (ESRI.ArcGIS.Geodatabase.IVersionedWorkspace)pWorkspace;

You can then iterate through all the versions.

//get a enumeration of all the versions on the versioned workspace
ESRI.ArcGIS.Geodatabase.IEnumVersionInfo enumVersionInfo = versionedWorkspace.Versions;
enumVersionInfo.Reset();

cbxVersion.Items.Clear();

ESRI.ArcGIS.Geodatabase.IVersionInfo versionInfo = enumVersionInfo.Next();
while (versionInfo != null)
{
string versionName = versionInfo.VersionName;
cbxVersion.Items.Add(versionName);
versionInfo = enumVersionInfo.Next();
}

Finally, don’t forget to close the connection.

init.Shutdown();

Here is what it looks like.

You can find an official example at the ESRI Resources Center.

ArcGIS Online: Create and share your maps

ESRI recently released their online version of ArcGIS, their leading software for georeferencing mapping.  The website is called ArcGIS Online and can be accessed through this address: http://www.arcgis.com/home/.

There is also a tool called ArcGIS Explorer Online that seems to be an alternative to Google Maps or Bing Maps… except the fact that it won’t tell you how to go from A to B! It still can be useful on some projects… but at this moment I can’t really see how someone can use this tool. If you have had any experience with it, why not share with us by posting a comment? 🙂