0

I have a mxd file with 6 layers. I want to get datasource information for each layer. Please see the code below. I want to know how exactly i should get layer's datasource information

IDocument doc = ArcMap.Application.Document;
IMxDocument mxDoc = doc as IMxDocument;
IMap map = mxDoc.FocusMap;
ILayer layer = map.get_Layer(0);// Layer[0];
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked May 23, 2018 at 19:11
5
  • Are you OK with an arcpy solution? It could be run interactively in the Python window in ArcGIS or via Python directly. Commented May 23, 2018 at 19:26
  • @smiller, I am creating an Add-In button and on click on this button i will grab datacource information. Since all of my code is currently in C# it would be great to have a C# solution. Commented May 23, 2018 at 19:35
  • Which information do you want to get? Commented May 23, 2018 at 20:11
  • @Kadir, I want Server, Connection Properties, Database, User name and although Password is not getting displayed in Layer Properties window but i would like to get password too only if its possible. Commented May 23, 2018 at 20:29
  • @smiller : I found the solution. Look at my answer Commented May 23, 2018 at 21:40

1 Answer 1

2

I have found the answer for my question. Please look at below mentioned code,

IDocument doc = ArcMap.Application.Document;
IMxDocument mxDoc = doc as IMxDocument;
IMap map = mxDoc.FocusMap;
ILayer layer = map.get_Layer(0);
ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = (ESRI.ArcGIS.Carto.IFeatureLayer)layer;
ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureLayer.FeatureClass;
ESRI.ArcGIS.Geodatabase.IDataset dataSet = (ESRI.ArcGIS.Geodatabase.IDataset)featureClass; 
ESRI.ArcGIS.esriSystem.IPropertySet propertySet = dataSet.Workspace.ConnectionProperties;
object propertyNames;
object propertyValues;
propertySet.GetAllProperties(out propertyNames, out propertyValues);
System.Array propNameArray = (System.Array)propertyNames;
System.Array propValuesArray = (System.Array)propertyValues;
answered May 23, 2018 at 21:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.