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

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Sep 12, 2014 at 14:05

2 Answers 2

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.

answered Sep 12, 2014 at 16:54
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?

Hornbydd
44.9k5 gold badges42 silver badges84 bronze badges
answered Sep 12, 2014 at 15:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.