Hey-
I am trying to programmatically access a lyr file and load it to the map. The lyr file is an XY Event Theme built using the 'Make XY Event Layer' tool in ArcToolbox. Accessing the lyr file is no problem, but when I try to get a handle on the event source and load it to the map, I get an error that says 'The XYEventSourceName has not been setup correctly'.
Here is the code I have for this block of the program, after I get the underlying layer from the lyr file:
if (layer instanceof IFeatureLayer) {
IDataLayer2 pDLayer = (IDataLayer2) layer
if (pDLayer.getDataSourceName() instanceof IXYEventSourceName) {
// Create and populate event properties
IXYEvent2FieldsProperties props = new IXYEvent2FieldsProperties();
props.setXFieldName("MAP_LONGITUDE");
props.setYFieldName("MAP_LATITUDE");
// Create spatial reference
ISpatialReferenceFactory refFactory - new SpatialReferenceEnvironment();
IGeographicCoordinateSystem spatRef = refFactory.createGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_NAD1927);
// Get a name object for source
IDataset sourceDataset = (IDataset) pDLayer;
IName sourceDsName = sourceDataset.getFullName();
// Create an XYEventSourceName
IXYEventSourceName xySrcNm = new XYEventSourceName();
xySrcNm.setEventPropertiesByRef(props);
xySrcNm.setSpatialReferenceByRef(spatRef);
xySrcNm.setEventTableNameByRef(sourceDsName);
// Create the XY Event Source
IName srcName = (IName) xySrcNm;
IXYEventSource xyEventSource = (IXYEventSource) srcName.open();
...
So it bombs on the srcNm.open() command, with the error that the event source name is not setup correctly. I think the problem is in the blue section, but that's just a guess. I have looked through several discussions, and got the gist of the code from http://forums.esri.com/Thread.asp?c=159&f=1707&t=303240. Any suggestions are appreciated.
Thanks,
MH
Well, we figured it out. It was the blue section, which was totally off. We had to create a TableName object and populate its' properties. Then we set the EventTableName of our EventSourceName to that TableName. We had to hard-code the name and namestring to our SDE layers, so will be revisiting to make it more dynamic. But hey, it's Friday afternoon, so it's all good now!