The following code demonstrates opening a feature class from a personal database and modifying a specified field alias, where it is important to note that it cannot be obtained directly from the Axmapcontrol in the engine, as
1 // get Ifeatureclass directly. 2 // ESRI. ArcGIS.Carto.ILayer lyr = mapctrl_main.get_layer (0); 3 // ESRI. ArcGIS.Carto.IFeatureLayer Flyr = (ESRI. ArcGIS.Carto.IFeatureLayer) Lyr; 4 // ESRI. ArcGIS.Geodatabase.IFeatureClass FC = Flyr. Featureclass;
This is not possible:
1 /// <summary>2 ///Modify the field alias.3 /// </summary>4 /// <param name= "Personalworkspacepath" >Personal database Path (can of course be a different type of database), such as "G:\doc\gis\1.400\data\pdb.mdb"</param>5 /// <param name= "Featureclassname" >feature class name, such as "Hyd1_4l_1"</param>6 /// <param name= "Orifieldname" >The original field alias, such as "Fnode_".</param>7 /// <param name= "Desfieldname" >The new field alias, such as "Fnode".</param>8 Private voidAlterfieldaliasname (stringPersonalworkspacepath,stringFeatureclassname,stringOrifieldname,stringdesfieldname) {9 //get Ifeatureclass through Ifeatureworkspace.TenESRI. ArcGIS.Geodatabase.IWorkspaceFactory WSF =NewESRI. ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass (); OneESRI. ArcGIS.Geodatabase.IWorkspace ws = WSF. Openfromfile (Personalworkspacepath,0); AESRI. ArcGIS.Geodatabase.IFeatureWorkspace FWS =(ESRI. ArcGIS.Geodatabase.IFeatureWorkspace) ws; -ESRI. ArcGIS.Geodatabase.IFeatureClass FC =FWS. Openfeatureclass (featureclassname); - theESRI. ArcGIS.Geodatabase.ITable T =(ESRI. ArcGIS.Geodatabase.ITable) FC; - if(T.findfield (orifieldname) = =-1)//No field name specified. - return; - +ESRI. ArcGIS.Geodatabase.IObjectClass objclass =(ESRI. ArcGIS.Geodatabase.IObjectClass) FC; -ESRI. ArcGIS.Geodatabase.ISchemaLock Slock =(ESRI. ArcGIS.Geodatabase.ISchemaLock) objclass; + Try { A Slock. Changeschemalock (ESRI. ArcGIS.Geodatabase.esriSchemaLock.esriExclusiveSchemaLock); atESRI. ArcGIS.Geodatabase.IClassSchemaEdit Cschemaedit =(ESRI. ArcGIS.Geodatabase.IClassSchemaEdit) T; - cschemaedit.alterfieldaliasname (Orifieldname, desfieldname); -MessageBox.Show (" Done"); - } - Catch(System.Exception ex) { - MessageBox.Show (ex. Message); in } - finally { to if(Slock! =NULL) + Slock. Changeschemalock (ESRI. ArcGIS.Geodatabase.esriSchemaLock.esriSharedSchemaLock); - } the}
Geodatabase-Modify Field alias (Fields alias)