Handling attachments in transformations

Amanda Ford asked on August 23, 2014 22:43

I'm trying to display attachments of documents in a repeater. I'm using this article as a reference: https://devnet.kentico.com/docs/7_0RC/devguide/index.html?handling_attachments_in_transformations.htm

The problem is this only works to display the attachments of the current document. I need to display each item in the repeater and their corresponding attachment.

For example: I want to display News items and each news item's attachments. The news page repeater would pull in this:

  • News item 1
  • News item attachments
  • News item 2
  • News item attachments

I realize that means creating a custom control, but I'm not sure how I might alter this code to grab the correct path:

using System;
using CMS.DataEngine;
using CMS.DocumentEngine;
using CMS.ExtendedControls;
using CMS.PortalEngine;
using CMS.Base;
using CMS.SiteProvider;

public partial class CMSInlineControls_DocumentAttachments : InlineUserControl
    #region "Methods"

    protected void Page_Load(object sender, EventArgs e)
        TreeNode currentDocument = DocumentContext.CurrentDocument;
        if (currentDocument != null)
            // Get document type transformation
            string transformationName = currentDocument.NodeClassName + ".attachment";
            TransformationInfo ti = TransformationInfoProvider.GetTransformation(transformationName);
            // If transformation not present, use default from the Root document type
            if (ti == null)
                transformationName = "cms.root.attachment";
                ti = TransformationInfoProvider.GetTransformation(transformationName);

            if (ti == null)
                throw new Exception("[DocumentAttachments]: Default transformation '" + transformationName + "' doesn't exist!");

            ucAttachments.TransformationName = transformationName;
            ucAttachments.SiteName = SiteContext.CurrentSiteName;
            ucAttachments.Path = currentDocument.NodeAliasPath;
            ucAttachments.CultureCode = currentDocument.DocumentCulture;
            ucAttachments.OrderBy = "AttachmentOrder, AttachmentName";
            ucAttachments.PageSize = 0;
            ucAttachments.GetBinary = false;
            ucAttachments.CacheMinutes = SettingsKeyInfoProvider.GetIntValue(SiteContext.CurrentSite + ".CMSCacheMinutes");


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