Update an attachment file

avdhoota n asked on May 8, 2017 15:27

I have a document type which has attachment in form of .png and .xlm files. A table which has this document fields has this attachment guid stored in it.

I want to update an attachment file contents manually, what is the best way. I have attachment GUID value, from form i will have HttpPostedFile object.

This update should not add any extra attachment but should update the existing one and attachmenthistory should have both the old and new one stored in it.

This adds a new attachement that i don't want, DocumentHelper.AddAttachment(node, fileAttachmentColumnName, path, tree);

setting attachmentInfo.AttachmentBinary to new file binary and using AttachmentInfoProvider.SetAttachmentInfo is the right way to update? please help me on this

Recent Answers


Brenden Kehren answered on May 8, 2017 15:38 (last edited on May 8, 2017 15:42)

I'd start out by looking at the Attachment API Examples and then looking at the DocumentHelper.GetAttachment() method to get your attachment by a GUID.

Using the SetAttachmentInfo() method will take the object you pass to it and either insert or update the object. It's smart enough to do either and I'd suggest using that method vs. the Update() method.

0 votesVote for this answer Mark as a Correct answer

avdhoota n answered on May 8, 2017 16:48

Thanks Brendon for your response.

Please let me know how to get AttachmentBinary from HttpPostedFile. Is there any kentico method to get it? asking a silly question but I am very new to kentico

0 votesVote for this answer Mark as a Correct answer

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