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()
FeatureClassopen()
AccessLayerViaMxDocument(My.ArcMap.Document)
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
mxdoc.AddLayer(fl)
mxdoc.ActiveView.Refresh()
mxdoc.UpdateContents()
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)
Debug.WriteLine(pMap.Name)
MsgBox(pMap.Name)
Dim pEnumLayer = pMap.Layers(Nothing, True)
pEnumLayer.Reset()
Dim pLayer As ILayer = pEnumLayer.Next()
Dim sb = New System.Text.StringBuilder()
While pLayer IsNot Nothing
Debug.WriteLine(pLayer.Name)
sb.Append(pLayer.Name).Append(vbLf)
pLayer = pEnumLayer.Next()
End While
MsgBox(sb.ToString())
Next
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)
Try
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
Next
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.