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];
-
Are you OK with an arcpy solution? It could be run interactively in the Python window in ArcGIS or via Python directly.SMiller– SMiller2018年05月23日 19:26:58 +00:00Commented 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.jay– jay2018年05月23日 19:35:15 +00:00Commented May 23, 2018 at 19:35
-
Which information do you want to get?Kadir Şahbaz– Kadir Şahbaz2018年05月23日 20:11:43 +00:00Commented 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.jay– jay2018年05月23日 20:29:54 +00:00Commented May 23, 2018 at 20:29
-
@smiller : I found the solution. Look at my answerjay– jay2018年05月23日 21:40:54 +00:00Commented May 23, 2018 at 21:40
1 Answer 1
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;
lang-cs