Select to view content in your preferred language

Listing Saved MXD and SDE Connection Layers using ArcObjects and C#

1321
1
08-29-2017 08:34 AM
BehrouzHosseini
Regular Contributor

Can you please let me know how I can list all layers inside a saved .mxd map and also get list of layers inside a SDE database connection using c# and ArcObjects? For example if I have a map document like "C:/GIS/Project.mxd" and a sde connection to enterprise geodatabase like "projects.sde" under database connection node, h lo w can I get access to them and list their contents?

I know how to do this using Python - ArcPy scripting like

import arcpy 
mxd = arcpy.mapping.MapDocument(r"C:\GIS\Project.mxd") 
df = arcpy.mapping.ListDataFrames(mxd, "")[0] 
for lyr in arcpy.mapping.ListLayers(mxd, "", df): 
    print lyr.name

But couldn't find a solution for ArcObject!

0 Kudos
1 Reply
AllanMills
Regular Contributor

I'm not sure about the SDE but for the MXD look at the IMapDocument interface and MapDocument class. You can use them to open an existing MXD. Each MapDocument can contain one or more maps which you can iterate through. For each map you can iterate through the layers inside of them.

0 Kudos