Ifeaturelayer to Ifeatureclass

740
3
02-10-2014 06:59 PM
jayakumar
New Contributor
Hi,

IMapDocument pmd = new MapDocumentClass();
            if (pmd.get_IsMapDocument(@"F:/Projects/Inprogress.mxd"))
            {
                pmd.Open(@"F:/Projects/Inprogress.mxd", null);
                IMap pmap = pmd as IMap;
               
                pmap = pmd.get_Map(0);
                Console.WriteLine(pmap.Name);//prints the Layer
                ILayer PL = pmap.get_Layer(1);
                Console.WriteLine(PL.Name);//prints the first layer
                IFeatureLayer FL = PL as IFeatureLayer;
                Console.WriteLine(FL.Name);//prints the first layer ofter typecasting to Feature Layer also
                IFeatureClass FC = FL.FeatureClass; //after this I want to print the fields and rows.
                  There is not compiler error, it is showing FC||Null

               How to move further..any help will be appreciated.

Thanks in advance
0 Kudos
3 Replies
NeilClemmons
Regular Contributor III
A null feature class means the data link is broken.  Make sure the mxd can access its data.
0 Kudos
AlexanderGray
Occasional Contributor III
even if the data link is broken you can still access many properties of the featureclass if you need.  The IDataLayer interface of FeatureLayer has DataSourceName which will be a featureclassName object which has the name and path of the featureclass among other things.
0 Kudos
RiverTaig1
Occasional Contributor
I beleive ILayer or IfeatureLayer has an IsValid property which you can check for in code.  The manifestation of InValid in ArcMap is whether that FeatureLayer is connected to something or not - in ArcMap, if you have ever seen a red exclamation in the Table of contents, your layer is disconnected, and IFeatureLayer:IsValid == false.
0 Kudos