This sample opens a shapefile on the user's local disk and adds the contents to the map as a feature layer. The default symbology is used. This sample could easily be changed to support different data sources.
The code samples in this section show the fundamentals of programming with ArcObjects. A careful reading of them gives you all the important concepts you need for developing with ArcObjects, as well as an introduction to the most important ArcObjects components.
The code can be typed or copied into the VBA environment in ArcMap or ArcCatalog, after which you can follow through with the VBA debugger.
How to use
- Add the code to the Click event of a UIButtonControl in ArcMap.
Dim pWorkspaceFactory As IWorkspaceFactory
Set pWorkspaceFactory = New ShapefileWorkspaceFactory
Dim pWorkSpace As IFeatureWorkspace
Set pWorkSpace = pWorkspaceFactory.OpenFromFile("C:\Source\", 0)
Dim pClass As IFeatureClass
Set pClass = pWorkSpace.OpenFeatureClass("USStates")
Dim pLayer As IFeatureLayer
Set pLayer = New FeatureLayer
Set pLayer.FeatureClass = pClass
pLayer.Name = pClass.AliasName
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
pMxDoc.FocusMap.AddLayer pLayer
pMxDoc.ActiveView.PartialRefresh esriViewGeography, pLayer, Nothing