HOW TO

Add hyperlinks to files that could be located in several subfolders

Last Published: November 9, 2020

Summary

Sometimes documents that must be hyperlinked to features are organized into several subfolders. This is typically done to organize large amounts of data into more manageable smaller folders. One challenge with organizing documents in this way is that it can create confusion when trying to hyperlink features to documents that could be in any of the subfolders of a primary directory. The following workflow is one method to recursively iterate through a directory to find and display documents that are associated with a feature, all through a Python script.

Procedure

In this example, the primary directory is called 'Parcels', but there are several subfolders underneath, breaking the Parcels directory down by zip code. This was done to better organize the data, but can cause confusion when creating hyperlinks in ArcMap. The hyperlinked file is a .jpeg image of the front of the property, and is named by using the Parcel ID.

[O-Image]
  1. Add the feature class to ArcMap, and open the layer properties. Right-click the layer and click Properties.
  2. Click the Display tab. Under Hyperlinks, check the Support Hyperlinks using field checkbox, click the Script radio button and click Edit.
[O-Image]
  1. At the bottom of the HyperLink Script dialog, select Python as the Parser.
  2. Use some Python code, similar to the following to recursively walk through a directory and find the associated Parcel image:
Code:
import webbrowser, os
def OpenLink([ParcelID]):
  for r,d,f in os.walk(r"\\serverName\Parcels"):
    for image in f:
      if image.startswith(str([ParcelID])):
        webbrowser.open(os.path.join(r,image))
  return
[O-Image]
  1. Click OK to close the Hyperlink Script and Layer Properties dialog boxes.
  2. On the Tools toolbar, click the Hyperlink button [O-Image], and click on a parcel in the map. If there is a picture associated with this parcel, it opens in whatever application the file type is associated with (by default, in Windows, a .jpeg file opens in Windows Photo Viewer).

Article ID: 000011828

Software:
  • ArcMap

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options