I'm using arcobjects (C#) to load my layers to the table of contents, and I need to update the data source to change the version.
The layer file is set to the correct source at the DEFAULT version. When a 'user' opens the MXD, i need to update the version just before it loads.
I'm not sure where to start with this. Here is the loading code:
var groupL = new GroupLayer();
groupL.Name = ALayerName;
var fileEntries = Directory.GetFiles(alayerDir, FileFilter).ToList();
fileEntries.ForEach(delegate(string path)
{
var layer = ActiveView.OpenLyrFromFile(path);
groupL.Add(layer);
});
return groupL;
So what to i need to cast 'layer' to in order to give the new version name and then restart the connection?
1 Answer 1
As I recall, you need to listen to IDocumentEvents
.
When OpenDocument
fires cast the IMxDocument to IDocumentDatasets
. For each IDatasetLayer2
in IDocumentDatasets.Datasets
:
Cast IDatasetLayer2.DataSourceName to IDataSetName.
Get (by value) IDatasetName.WorkspaceName
.
Get (by value) the propertyset from IWorkspaceName.ConnectionProperties
.
Change the "VERSION" property in the propertyset to whatever version you want.
Assign the property set back to IWorkspaceName.ConnectionProperties
.
Assign the workspacename back to IDatasetName.WorkspaceName
,
Assign the datasetname back to IDatasetLayer2.DatasourceName
.
Alternatively, you might want to call IDatasetLayer2.Connect
, passing the modified datasetname.
-
I changed it a bit, but creating the propertyset dynamically (with the version set) and create a new sde. I then change the layer workspace to the new SDE.Omnia9– Omnia92016年04月07日 15:27:09 +00:00Commented Apr 7, 2016 at 15:27