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];
  • Are you OK with an arcpy solution? It could be run interactively in the Python window in ArcGIS or via Python directly. – smiller May 23 '18 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 May 23 '18 at 19:35
  • Which information do you want to get? – Kadir Şahbaz May 23 '18 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 May 23 '18 at 20:29
  • @smiller : I found the solution. Look at my answer – jay May 23 '18 at 21:40
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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.