Export Attachments (Data Management)

Summary

Exports file attachments from the records of a geodatabase feature class or table to a specified folder. Attachments can also be exported to subdirectories based on an attribute value from a specified attribute column. Exported attachments can be renamed using one or more field attribute values.

Learn more about working with the Attachments geoprocessing tools

Usage

  • This tool honors selections. If no records are selected, all attachments will be exported.

  • Exported attachment files will be the same file type as when added to the geodatabase. For example, if the attachment is a .pdf file, the exported file will be a .pdf.

  • Attachments can be exported to subdirectories for each record by specifying a value for the Subdirectory Field parameter. Values from the field will be used to name the subdirectories. For example, if the attribute table has three rows, and the values of the selected field are ATL, TPA, and SLC, three subdirectories with these names will be created. All attachments for each of these values will be downloaded into their respective subdirectory.

  • To avoid name conflicts in the exported files, the tool will add an incremental number to file names when appropriate. If a field value is null, the word None is used in the file name.

  • When exporting attachments, the following characters from field values will be replaced in the output subdirectories and file names:

    Field value charactersReplaced with

    Forward slash (/)

    Hyphen (-)

    Double backslash (\\)

    Hyphen (-)

    Pipe or vertical Line (|)

    Hyphen (-)

    Asterisk (*)

    Underscore (_)

    Less than (<)

    Underscore (_)

    Greater than (>)

    Underscore (_)

    Question mark (?)

    Underscore (_)

    Colon (:)

    A comma followed by a space (, )

Parameters

LabelExplanationData Type
Input Dataset

The geodatabase table or feature class from which attachments will be exported.

The input must be stored in a version 10.0 or later geodatabase, and the table must have attachments enabled.

Table View
Output Location

The folder where the attachment files will be exported.

Folder
Subdirectory Field
(Optional)

A field from the Input Dataset parameter value that will be used to create subdirectory names.

Field
Name Format
(Optional)

Specifies the format that will be used for naming exported attachments.

  • Use Original FilenamesThe output file names will use the original file names stored in the geodatabase.
  • Use Field Values OnlyThe output file names will use the field values of the Name Fields parameter values. Multiple values will be concatenated with an underscore.
  • Add Field Values as PrefixThe output file names will use the original file names with a prefix from the field values of the Name Fields parameter values.
  • Add Field Values as SuffixThe output file names will use the original file names with a suffix from the field values of the Name Fields parameter values. Multiple values will be concatenated with an underscore.
String
Name Fields
(Optional)

The field names from the Input Dataset parameter value that will be used to rename the exported attachments. If multiple fields are specified, the output files will use the field values concatenated with an underscore in the order they are specified.

For example, if two field names are specified, and Name Format parameter is set to Use Field Values Only, the field values for the first record are Main and Street, and the attachment is a .jpg file, the exported file will be named Main_Street.jpg.

This parameter is enabled when the Name Format parameter is set to Use Field Values Only, Add Field Values as Prefix, or Add Field Values as Suffix.

Field

Derived Output

LabelExplanationData Type
Output Directories

The updated folders.

Folder

arcpy.management.ExportAttachments(in_dataset, out_location, {subdirectory_field}, {name_format}, {name_fields})
NameExplanationData Type
in_dataset

The geodatabase table or feature class from which attachments will be exported.

The input must be stored in a version 10.0 or later geodatabase, and the table must have attachments enabled.

Table View
out_location

The folder where the attachment files will be exported.

Folder
subdirectory_field
(Optional)

A field from the in_dataset parameter value that will be used to create subdirectory names.

Field
name_format
(Optional)

Specifies the format that will be used for naming exported attachments.

  • ORIGINALThe output file names will use the original file names stored in the geodatabase.
  • REPLACEThe output file names will use the field values of the name_fields parameter values.
  • PREFIXThe output file names will use the original file names with a prefix from the field values of the name_fields parameter values.
  • SUFFIXThe output file names will use the original file names with a suffix from the field values of the name_fields parameter values.
String
name_fields
[name_fields,...]
(Optional)

The fields from the in_dataset parameter value that will be used to rename the exported attachments. If multiple fields are specified, the output files will use the field values concatenated with an underscore in the order they are specified.

For example, if two field names are specified, and name_format parameter is set to REPLACE, the field values for the first record are Main and Street, and the attachment is a .jpg file, the exported file will be named Main_Street.jpg.

This parameter is enabled when the name_format parameter is set to REPLACE, PREFIX, or SUFFIX.

Field

Derived Output

NameExplanationData Type
out_dirs

The updated folders.

Folder

Code sample

ExportAttachments example 1 (Python window)

The following code snippet demonstrates how to use the ExportAttachments function in the Python window.

import arcpy
arcpy.management.ExportAttachments(r"C:\Data\National.gdb\Airports",
                                   r"C:\OutputFolder", 'CODE', 'REPLACE', ['NAME', 'CODE'])
ExportAttachments example 2 (stand-alone script)

Use the ExportAttachments function to export attachments for a specific feature after performing a selection on the data source.

import arcpy

# Import system variables
import arcpy

# Set the workspace
arcpy.env.workspace = r"C:\National.gdb"

# Set local variables
in_dataset = "Airports"
out_location = r"C:\Output_Images"
subdir_field = 'Code'
output_names = 'REPLACE'
name_fields = ['NAME', 'CODE']

# Select the Salt Lake City Airport and download all attachments to a subdirectory named SLC.
layerSelection = arcpy.management.SelectLayerByAttribute(in_dataset, 'NEW_SELECTION',
                                                         "Name = 'Salt Lake City'")

# Export the attachments with the layer selection set and renamed using field values.
arcpy.management.ExportAttachments(layerSelection, out_location, subdir_field,
                                   output_names, name_fields)

Environments

This tool does not use any geoprocessing environments.

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics