HOW TO

Get the full path of a layer using ArcObjects

Last Published: April 25, 2020

Summary

This article contains a code sample that shows how to get the full path of a layer using VBA.

Procedure



  1. Open ArcMap.
  2. Open the Visual Basic Editor.

    In ArcMap, select Tools > Macros > Visual Basic Editor.

  3. In the Project Explorer window, expand Project.mxt and select ArcMap Objects > ThisDocument then right-click and select View Code.
    [O-Image] Visual Basic Project  Explorer

    Note:
    Code in the Project's ThisDocument code module will only run in the current map document. If you want to store the code in all your map documents open the Normal.mxt ThisDocument code module instead.

  4. Paste the following code into the code module.

    Code:
    Sub GetLayerPath()
    Dim pDoc As IMxDocument
    Set pDoc = ThisDocument
    'Get the first map in the document
    Dim pMap As IMap
    Set pMap = pDoc.FocusMap
    'Get the first layer in the map
    Dim pLayer As IFeatureLayer
    Set pLayer = pMap.Layer(0)
    'Get the feature class for the first layer
    Dim pFc As IFeatureClass
    Set pFc = pLayer.FeatureClass
    'Gets the dataset for standalone feature class
    Dim pDataset As IDataset
    Set pDataset = pFc
    Dim pWorkspace As IWorkspace
    Set pWorkspace = pDataset.Workspace
    Debug.Print pWorkspace.PathName
    End Sub

  5. Close the Visual Basic Editor.
  6. Run the code.

    A. Click Tools > Macros > Macros to display the Macros dialog box.
    B. Select a macro and click Run.

Article ID:000004948

Software:
  • ArcMap 9 x
  • ArcMap 8 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic