English

How To: Add hyperlinks to files that could be located in several subfolders

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 parent 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 parent directory is called 'Parcels', but there are several subfolders underneath, breaking the Parcels 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, select the 'Support Hyperlinks using field' checkbox, click the 'Script' radio button and click Edit.
    [O-Image]
  3. At the bottom of the HyperLink Script dialog, select Python as the Parser.
  4. 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]
  5. Click OK to close the Hyperlink Script and Layer Properties dialog boxes.
  6. 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).