Bug reports Found a bug? Post it here please.
Version 7.x > Bug reports > Attachment not accessible until document is published View modes: 
User avatar
Certified Developer 8
Certified Developer 8
matthew.mason-fcv - 7/22/2013 1:24:16 PM
   
Attachment not accessible until document is published
Hi,

I'm currently experiencing an issue with a document type that can have attachments added to it via a File attribute.
This document is then exposed via a repeater and a transform. Everything was working perfectly until we turned on Workflows to enable previewing/publishing of content.

Now, if a new document of this type is created, an attachment added and the document is previewed an error is rendered by the repeater control because it can't find the attachment when the transform is applied:
User image

This is the transformation used:
User image

It appears that when you upload the attachment as you create the document, it is placed in the CMS_Attachment table fine. Upon clicking 'Save' it's moved to 'CMS_AttachmentHistory' and deleted from 'CMS_Attachment' and only moved back when you click 'Publish'.

I'm just wondering if there are any changes that can be made to the configuration to prevent this behavior or can I change the transformation so that it can access the attachment in 'CMS_AttachmentHistory' should it not be found in 'CMS_Attachment'?

Many thanks.

User avatar
Member
Member
kentico_sandroj - 7/22/2013 3:37:37 PM
   
RE:Attachment not accessible until document is published
Hello,

The best approach would be to create a custom function that checks if the attachment is available in CMS_Attachment and if not, use the CMS_AttachmentHistory Version.

This would be a better approach than modifying a core functionality of the system. Please let me know if you have any questions.

Regards,
Sandro

User avatar
Certified Developer 8
Certified Developer 8
matthew.mason-fcv - 7/22/2013 3:40:15 PM
   
RE:Attachment not accessible until document is published
Thanks for the reply Sandro,

This is something I had thought a little about, but I'm just wondering, are there any specific, built-in methods I can use to retrieve the AttachmentHistory version?

Regards,

Matt.

User avatar
Member
Member
kentico_sandroj - 7/22/2013 4:30:18 PM
   
RE:Attachment not accessible until document is published
Hi,

You can get AttachmentInfo object from your AttachmentGUID and then you can access AttachmentLastHistoryID property:

// Always work with some user when editing documents
UserInfo ui = UserInfoProvider.GetUserInfo("administrator");

TreeProvider tree = new TreeProvider(ui);

// Create the attachment manager
AttachmentManager am = new AttachmentManager(tree.Connection);

// Get the attachment

AttachmentInfo existingAttachment = am.GetAttachmentInfo(existingGuid, CMSContext.CurrentSite.SiteName);

existingAttachment.AttachmentLastHistoryID

Attachment API Examples

Is this what you are looking for? Please let me know if I can be of any further assistance.

Thanks,
Sandro