I'm a novice in programming:

I'm trying to create a code which gives me the alias name from the attribute table. This is the code below that I tried, but it gives me only the layernames instead of alias name:

Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.ArcMapUI
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.DataSourcesGDB
Imports ESRI.ArcGIS.Display

Public Class Aliasname Inherits ESRI.ArcGIS.Desktop.AddIns.Button

    Public Sub New()
    End Sub

    Protected Overrides Sub OnClick()
        My.ArcMap.Application.CurrentTool = Nothing
    End Sub 

    Public Sub FeatureClassopen()
        Dim wsf As IWorkspaceFactory = New FileGDBWorkspaceFactoryClass()
        Dim gdbFileAddress As String = "C:\worki\samples.gdb"
        Dim ws As IWorkspace = wsf.OpenFromFile(gdbFileAddress, My.ArcMap.Application.hWnd)

        Dim fws As IFeatureWorkspace = ws
        Dim fc As IFeatureClass = fws.OpenFeatureClass("abc")

        Dim fl As IFeatureLayer = New FeatureLayerClass()
        fl.Name = "abc"
        fl.FeatureClass = fc
        Dim mxdoc As IMxDocument = My.ArcMap.Application.Document
    End Sub   

    Shared Sub LayerViaMxDocument(ByVal pMxDocument As IMxDocument)
        Dim pMap As IMap
        Dim pMaps As IMaps = pMxDocument.Maps
        Dim i As Integer
        For i = 0 To pMaps.Count - 1
            pMap = pMaps.Item(i)
            Dim pEnumLayer = pMap.Layers(Nothing, True)
            Dim pLayer As ILayer = pEnumLayer.Next()
            Dim sb = New System.Text.StringBuilder()
            While pLayer IsNot Nothing
                pLayer = pEnumLayer.Next()
            End While
    End Sub

    'Funktion not fuctional
    Function Numbreoftable(ByVal workspace As IFeatureWorkspace, ByVal tableName As String) As Integer
        ' table open
        Dim table As ITable = workspace.OpenTable(tableName)
        ' number of fields
        Return table.Fields.FieldCount
    End Function

    ' not functional
    Public Sub ShowDistinctFieldAliasNames(pFClass As ESRI.ArcGIS.Geodatabase.IFeatureClass)
            Dim fields As ESRI.ArcGIS.Geodatabase.IFields = pFClass.Fields
            Dim field As ESRI.ArcGIS.Geodatabase.IField

            For i As Integer = 0 To fields.FieldCount - 1
                field = fields.Field(i)
                If field.Name <> field.AliasName Then
                    Debug.WriteLine(field.Name & ", " & field.AliasName)
                End If
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.ToString, "Sub Error", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Error)
        End Try
    End Sub  

    Protected Overrides Sub OnUpdate()
        Enabled = My.ArcMap.Application IsNot Nothing
    End Sub

End Class

I don't know what I'm doing wrong. Maybe someone can help me finding a solution.


If you want to get the alias name of the underlying feature class, you have to cast the layer as an IFeatureLayer, and then grab the AliasName from the featurelayer.featureclass. See my code:

Dim enumLayer As IEnumLayer = My.ArcMap.Document.FocusMap.Layers(Nothing, True)
Dim layer As ILayer = enumLayer.Next
Do Until layer Is Nothing
    If TypeOf layer Is IFeatureLayer Then
        Dim fl As IFeatureLayer = CType(layer, IFeatureLayer)
        MessageBox.Show(String.Format("Layer {0} has an alias name of {1}", layer.Name, fl.FeatureClass.AliasName))
    End If
    layer = enumLayer.Next

EDIT: To get the alias name of each field in the attribute table, you will need to grab the fields object either from a feature or featureclass object. See below. I just grab a reference to a featureclass from a featurelayer.

Dim fc as IFeatureClass = fl.FeatureClass
Dim fields as IFields = fc.Fields

for i = 0 to fields.FieldCount - 1
    Dim field As IField = fields.Field(i)
  • thanks for your help. but I think it's not what I need. I need the aliasname of the attribute table of the featurelayer. Maybe you have a solution for the case as well. – Betti Apr 19 '17 at 20:47
  • I think you may be using the wrong terminology. Do you need the names/alias names of the fields in the attribute table? – Barbarossa Apr 19 '17 at 21:01
  • One more addition: I search for each field.aliasname of the attribute table. – Betti Apr 19 '17 at 21:01
  • Yes I think, that is what I am looking for :-) – Betti Apr 19 '17 at 21:03
  • Thank you so much. When I look at my code, I do not need much at all. The code I had synonymous times as a stand-alone function. This did not work.My last question what of my code do I really need and is the arrangement correct? – Betti Apr 19 '17 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.