3

I am attempting to access a feature's attachments in ArcObjects and I'm following the docs for Working with feature attachments. Everything is fine until attempt to access IAttachment.Data because I am expecting there to be data, but that property is null:

enter image description here

which means I can't proceed past: IMemoryBlobStream memoryBlobStream = attachment.Data;

I am thinking there is a missing step (or steps) in the docs that would fill the attachment object's Data property with actual data? How is this done?

I am able to access the attachment via the Identify window within ArcMap, so I know the data is there:

enter image description here

enter image description here

enter image description here

3

The issue was a combination of me copying the wrong snippet of code and not fully reading the docs that I had referenced in my question!

The Boolean parameter ("Info Only") of these methods determines which properties of the returned attachments will be populated.

I had copied:

IEnumAttachment enumAttachment = attachmentManager.GetAttachmentsByParentIDs (parentIdArray, true);

Changing it to false brings brings back the .Data value:

IEnumAttachment enumAttachment = attachmentManager.GetAttachmentsByParentIDs (parentIdArray, false);

Both lines of code are present in the docs.

2

I have never done this using the .NET SDK, but I have used this python script in the past:

import arcpy, os, sys
arcpy.env.overwriteOutput = True

def extract_attachments(out_ws, table, blob_field, filename_fld):
    '''
    Code adopted from "Another GIS Blog"
        http://anothergisblog.blogspot.nl/2012/06/working-with-blob-data-at-101-arcpyda.html

    """ Exports all attachments from a geodatabase to a new location """

    Required:
    out_ws -- location for attachments
    table -- table or feature class containing attachment info
    blob_field -- field containing attachment files
    filename_fld -- field name containing file name
    '''

    # make sure out_ws exists, if not create
    if not os.path.exists(out_ws):
        os.makedirs(out_ws)

    # search cursor
    c = 0
    with arcpy.da.SearchCursor(table, ['REL_OBJECTID', blob_field, filename_fld]) as rows:
        for row in rows:
            roid, binRep, fileName = row
            if binRep:
                out_file = os.path.join(out_ws, 'OID_' + '_'.join(map(str, [roid, fileName])))
                open(out_file, 'wb').write(binRep.tobytes())
                c += 1

    arcpy.AddMessage('Exported {0} attachments to: "{1}"'.format(c, out_ws))
    return

if __name__ == '__main__':

    # run as script tool
    extract_attachments(*sys.argv[1:])

Does this have to be done in ArcObjects?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.