AnsweredAssumed Answered

Add DBF file to ArcMAP Table of Contents

Question asked by dwolford on Jun 18, 2012
Latest reply on Jun 18, 2012 by dwolford
This is my second program using ArcObjects and I am having some technical difficulties.  I have another program I wrote that will allow you to select
tabular information from Excel and Save that to a Dbase *.dbf file where you can provide field attribute information.  This program will be an ArcMap
Add-in that will run the previously mentioned program creating a DBF file.  This DBF file will then be added to open ArcMAP file and then be joined to
an existing SHP file.  I am running 64-bit Windows 7 Professional with Visual Studio Express 2008.

The full source code is in the attached zip file and contains the four routines discussed below.  I only included the AddDBFLayer in this posting.
The routines in the code below is mostly borrowed from ESRI Samples and are all basically just to add the DBF file to ArcMAP.  Each of these programs
have there own errors that are listed in the code.  I would not be surprised if I am not properly assigning the Map Application or the Map Document
variables.  Currently I have 4 main programs called when(OnClick) button is selected.  These 4 programs are just 4 different ways I have attempted to
solve my problem, and I am looking for one good one.

1.) AddDBF - This program gives no errors but does not add the DBF to the Table of Contents?
2.) AddDBFLayer  - This program Calls AddTable which calls OpenTable.  The error occurs when trying to open the table.
3.) AddShapefile -  Error occurs when trying to open the shapefile
4.) AddShapefile2 - Error occurs when trying to open the shapefile.                  

Any and all help would be greatly appreciated.

Thanks
Dan
Imports ESRI.ArcGIS.CatalogUI Imports ESRI.ArcGIS.Framework Imports ESRI.ArcGIS.esriSystem Imports ESRI.ArcGIS.Desktop Imports ESRI.ArcGIS.ArcMapUI Imports ESRI.ArcGIS.DataSourcesFile Imports ESRI.ArcGIS.Geodatabase Imports ESRI.ArcGIS.Carto Imports ESRI.ArcGIS.Geometry Imports ESRI.ArcGIS.Display Imports System.IO Imports ESRI.ArcGIS.ADF Imports System.Drawing  Public Class btnXLStoDBF     Inherits ESRI.ArcGIS.Desktop.AddIns.Button     Private m_application As ESRI.ArcGIS.Framework.IApplication     Private mx_application As ESRI.ArcGIS.ArcMapUI.IMxApplication '*********************************************************************************************************************************************         Protected Overrides Sub OnClick()         '**EXECUTES THIS CODE WHEN BUTTON IS PRESSED IN ARCMAP         Call AddDBF()         Call AddDBFLayer()         Call AddShapefile()         Call AddShapefile2()     End Sub     Protected Overrides Sub OnUpdate()         Enabled = My.ArcMap.Application IsNot Nothing     End Sub     Public Sub AddDBFLayer()         Try             'Dim eApp As IMxApplication = My.ThisApplication             'Dim App As ESRI.ArcGIS.Framework.IApplication = My.ThisApplication             Dim pDoc As IMxDocument = My.ArcMap.Document             Dim pMap As IMap = pDoc.FocusMap             Call AddTable(pMap, pDoc)     End Sub     Public Sub AddTable(ByVal map As IMap, ByVal mxDocument As IMxDocument)         'SOURCE OF THE FOLLOWING SUBROUTINES: ArcObjects SDK 10 MS .NET Framework: Concepts and Samples         'ArcObjects Help for .NET developers\Developting with ArcGIS\Learning ArcObjects\Interacting with and configuring maps, layers, and graphics\         'Working with the Map\Performing basic map functions         'http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Performing_basic_map_functions/000100000147000000/         Dim tableCollection As ITableCollection = TryCast(map, ITableCollection)         Dim tablePathName As String = "C:\Users\dwolford\Documents\Visual Studio 2008\Projects\XLStoDBF\XLStoDBF\SHP\FINAL"         Dim tableName As String = "RT010-61-880-FINAL.DBF"         Dim table As ITable = OpenTable(tablePathName, tableName)         If (table Is Nothing) Then             Return         Else             tableCollection.AddTable(table)             mxDocument.UpdateContents()         End If     End Sub     Public Function OpenTable(ByVal pathName As String, ByVal tableName As String) As ITable         ' Create the workspace name object.             Dim workspaceName As IWorkspaceName = New WorkspaceNameClass()             workspaceName.PathName = pathName             workspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.shapefileworkspacefactory"         ' Create the table name object.             Dim dataSetName As IDatasetName = New TableNameClass()             dataSetName.Name = tableName             dataSetName.WorkspaceName = workspaceName         ' Open the table.             Dim Name As IName = TryCast(dataSetName, IName)             Dim table As ITable = TryCast(Name.Open(), ITable)  '<--ERROR HERE                     '    Error -2147220655: Exception from HRESULT: 0x80040351                     '    Systems.Collections.ListDictionaryInternal         Return table     End Function End Class

Attachments

Outcomes