DirectoryInfo di = new DirectoryInfo(folder); FileInfo[] files = di.GetFiles("*.mxd"); Dictionary<string, List<String>> referencedFiles = new Dictionary<string,List<string>>(); foreach (FileInfo fi in files) { referencedFiles.Add(fi.FullName, new List<string>()); IMapDocument doc = new MapDocument(); doc.Open(fi.FullName); doc.SetActiveView(doc.PageLayout as IActiveView); doc.ActiveView.Activate(0); IEnumLayer pEnumLayer = doc.ActiveView.FocusMap.Layers; pEnumLayer.Reset(); ILayer pLayer; while ((pLayer = pEnumLayer.Next()) != null) { IFeatureLayer pFL = pLayer as FeatureLayer; IFeatureClass pFC = pFL as IFeatureClass; // pFC is coming up null every time for all shapefile layers. } }
foreach (FileInfo fi in files) { IMapDocument pMapDoc = new MapDocumentClass(); if (pMapDoc.get_IsMapDocument(fi.FullName)) { pMapDoc.Open(fi.FullName, null); IMap pMap; for (int i = 0; i <= pMapDoc.MapCount - 1; i++) { pMap = pMapDoc.get_Map(i); IEnumLayer pEnumLayer = pMap.get_Layers(null, true); pEnumLayer.Reset(); ILayer pLayer = pEnumLayer.Next(); while (pLayer != null) { IFeatureLayer pFtrLayer = pLayer as IFeatureLayer; if (pFtrLayer != null) { IFeatureClass pFtrClass = pFtrLayer.FeatureClass; if (pFtrClass != null) { IDataset pDataset = pFtrClass as IDataset; if (pDataset != null) { \\pDataset.Name \\pDataset.Workspace.PathName } } } pLayer = pEnumLayer.Next(); } } }
Hi all:
I'm having difficulty trying to programatically access the data source for layers within an mxd. Code follows:DirectoryInfo di = new DirectoryInfo(folder); FileInfo[] files = di.GetFiles("*.mxd"); Dictionary<string, List<String>> referencedFiles = new Dictionary<string,List<string>>(); foreach (FileInfo fi in files) { referencedFiles.Add(fi.FullName, new List<string>()); IMapDocument doc = new MapDocument(); doc.Open(fi.FullName); doc.SetActiveView(doc.PageLayout as IActiveView); doc.ActiveView.Activate(0); IEnumLayer pEnumLayer = doc.ActiveView.FocusMap.Layers; pEnumLayer.Reset(); ILayer pLayer; while ((pLayer = pEnumLayer.Next()) != null) { IFeatureLayer pFL = pLayer as FeatureLayer; IFeatureClass pFC = pFL as IFeatureClass; // pFC is coming up null every time for all shapefile layers. } }
I've already tried the first solution before attempting to use the active view.
As for the second, I'm not looking to use the GUI, this is a console app, therefore IApplication / IMxDocument is not going to work for me.
Hi all:
I'm having difficulty trying to programatically access the data source for layers within an mxd. Code follows:DirectoryInfo di = new DirectoryInfo(folder); FileInfo[] files = di.GetFiles("*.mxd"); Dictionary<string, List<String>> referencedFiles = new Dictionary<string,List<string>>(); foreach (FileInfo fi in files) { referencedFiles.Add(fi.FullName, new List<string>()); IMapDocument doc = new MapDocument(); doc.Open(fi.FullName); doc.SetActiveView(doc.PageLayout as IActiveView); doc.ActiveView.Activate(0); IEnumLayer pEnumLayer = doc.ActiveView.FocusMap.Layers; pEnumLayer.Reset(); ILayer pLayer; while ((pLayer = pEnumLayer.Next()) != null) { IFeatureLayer pFL = pLayer as FeatureLayer; IFeatureClass pFC = pFL as IFeatureClass; // pFC is coming up null every time for all shapefile layers. } }