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
Solved! Go to Solution.