How To: Add hyperlinks to features using ArcObjects


This article provides an example of programmatically creating hyperlinks for selected features using ArcObjects.



  1. Start ArcMap.
  2. Create a new UIButtonControl: How To: Create a new UIButtonControl
    For more information on creating a UIControl, see the ArcGIS Desktop Help topic: 'Creating custom commands with VBA and UI Controls'
  3. Right-click the UIButtonControl and select View Source.
  4. Copy this code into the UIButtonControl's click event.
    Dim pMxDoc As IMxDocument
    Dim pMap As IMap
    Dim pLayer As IFeatureLayer
    Dim pHyperlink As IHyperlink
    Dim pHyperlinkContainer As IHyperlinkContainer
    Set pMxDoc = ThisDocument
    Set pMap = pMxDoc.FocusMap
    'Get the selected features from the layer
    Set pLayer = pMxDoc.SelectedLayer
    If pLayer Is Nothing Then
      MsgBox "Please select a layer"
      Exit Sub
    End If
    Dim pFSel As IFeatureSelection
    Set pFSel = pLayer
    Dim pSelSet As ISelectionSet
    Set pSelSet = pFSel.SelectionSet
    'Make sure features are selected
    If pSelSet.Count < 1 Then
      MsgBox "Please select some features"
      Exit Sub
    End If
    'Get the hyperlink from the user
    Dim strLink As String
    strLink = InputBox("Enter the Hyperlink", "Get Hyperlink")
    'Loop through the selected features and add the hyperlink
    Dim pFeature As IFeature
    Dim pCur As IFeatureCursor
    pSelSet.Search Nothing, False, pCur
    Set pFeature = pCur.NextFeature
    'The layer to add hyperlinks
    Set pHyperlinkContainer = pLayer
    Do Until pFeature Is Nothing
      Set pHyperlink = New Hyperlink
      pHyperlink.LinkType = esriHyperlinkTypeURL
      pHyperlink.Link = strLink
      pHyperlink.FeatureId = pFeature.OID
      pHyperlinkContainer.AddHyperlink pHyperlink
    Set pFeature = pCur.NextFeature
  5. Select a layer in the Table of Contents.
  6. Select the features to hyperlink and press the newly created button.
  7. Enter the hyperlink when prompted.