Get Feature Class Name Using ArcObject

Introduction

In this blog, we are trying to find the actual name of the feature class using ArcObject. If we try to get the feature class name using ArcObject by default, it will give us the alias name instead of the actual name. The alias name may be blank because this is not the mandatory condition to provide the alias name for the feature class. Once we start with ArcObject, if we are getting a blank name, our program may be stuck somewhere. So, to get rid of this problem, we have to get the actual name of the feature class.

Description

We have some shapefiles and we want to get the actual name of the shapefile instead of the alias name. First, we get the object of workspace factory. From workspace factory, we will use method openFromFile and get the object of the workspace. After casting that workspace in the feature workspace, we can get the object of the feature class using method OpenFeatureclass. In our example, we have featureclass "LanduseA" and we want to get the actual name of this class.We cast the feature class in idataset and then we can use a property of name in idataset and we will get the actual name of the feature class.That piece of code is applicable on shape file, Personal GDB and File Geodatabase as well.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Windows.Forms;  
  8. using ESRI.ArcGIS.DataSourcesFile;  
  9. using ESRI.ArcGIS.DataSourcesGDB;  
  10. using ESRI.ArcGIS.Geodatabase;  
  11. using ESRI.ArcGIS.esriSystem;  
  12. using ESRI.ArcGIS.Geometry;  
  13. using System.Collections;  
  14. namespace WindowsApp {  
  15.     public partial class Form1: Form {  
  16.         public Form1() {  
  17.             InitializeComponent();  
  18.         }  
  19.         private void button1_Click(object sender, EventArgs e) {  
  20.             IWorkspaceFactory pwsf = new ShapefileWorkspaceFactory();  
  21.             IWorkspace pws = pwsf.OpenFromFile(@ "D:\YS\ShapeFiles", 0);  
  22.             IFeatureWorkspace pfeatWs = (IFeatureWorkspace) pws;  
  23.             IFeatureClass pfc = pfeatWs.OpenFeatureClass("LandUseA.shp");  
  24.             IDataset pds = (IDataset) pfc;  
  25.             string name = pds.Name;  
  26.         }  
  27.     }  
  28. }  
Next Recommended Reading Read Shape Files Using ArcObject