Get attachments from TreeNode using field name

Andy Bochmann asked on June 28, 2019 21:13


I'm trying to get attachments from a certain field from the TreeNode object. For example, for strings, you can do node.GetStringValue("Title"). I'd like to do the same for attachments, however, there is no node.GetAttachments(fieldName) method.

I've already looked at DocumentHelper.GetAttachments(), but I'm not sure how to filter the result by field name.

I saw that the generated page type classes use node.GetFieldDocumentAttachments(fieldName), however, that method is protected, so I can't use it directly. Is there a public methods somewhere that I can use to get the same result?

Thank, Andy

Correct Answer

Mike Wills answered on June 28, 2019 22:45

Hi Andy,

You can use node.GetValue(fieldName) to first get the attachment guids. Then you can use node.AllAttachments to get the AttachmentInfo object by guid.

If you need to get attachments for many nodes, you can save some SQL Server round trips, by getting all the attachment guids for several nodes, and then use something like the following to get all AttachmentInfo objects in one round trip:

var attachments = AttachmentInfoProvider.GetAttachments()
            .WhereIn("AttachmentGUID", attachmentGuids);


0 votesVote for this answer Unmark Correct answer

Recent Answers

Andy Bochmann answered on June 29, 2019 02:05

Thank you very much for the quick reply. I'll try that.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.