How to get Table Name from TOC

826
1
05-10-2012 07:30 AM
JoshV
by
Occasional Contributor
I'm using C# to get the actual datasourcename of each layer in the Table of Contents of an MXD (example: sde.SomeDatabase.Cities is the datasourcename for the Cities Table).  My code is blowing up when I try to capture this datasourcename so is my code not right or are there better ways to capture this name for a Table?


                            IStandaloneTable pStTable;
                            ITable pFromTable;
                            ILayer pTableLayer;
                            IDataLayer pDatalyr;

                            pTabCollection = pMap as IStandaloneTableCollection;
                            for (int u = 0; u < pTabCollection.StandaloneTableCount; u++)
                            {
                                pFromTable = pTabCollection.StandaloneTable as ITable;
                                pDatalyr = pFromTable as IDataLayer;
 
                                string test = pDataLayer.DataSourceName.ToString().ToUpper(); //Code blowing up here

                                //.......... additional code
                              }

0 Kudos
1 Reply
JoshV
by
Occasional Contributor
I needed to use IStandalonetable.  Updated code below.  Thanks

 IStandaloneTable pStTable;
                            ITable pFromTable;
                            ILayer pTableLayer;
                            IDataLayer pDatalyr;
                            pTabCollection = pMap as IStandaloneTableCollection;
                            for (int u = 0; u < pTabCollection.StandaloneTableCount; u++)
                            {
                                tbltracker = 0;
                                pStTable = pTabCollection.StandaloneTable;  //added
                                pDatalyr = pStTable as IDataLayer;
                                pFromTable = pStTable as ITable;
0 Kudos