How to display a list of group attachments in selected item transformation

   —   
This article gives an example of how to show the group attachments in selected item transformation within a repeater web part.
In this example we will work with custom document type called customProduct, which will have the following fields:

Name field


Documents field


After you create the document type, you will need to place the repeater web part on the page, then open the properties of repeater, go to Transformations section, and click on the New button next to the Transformation property.

Insert any name, and then put the following code into the transformation (please note that it is necessary to select ASCX transformation type):
<%@ Register Src="~/CMSModules/Content/Controls/Attachments/DocumentAttachments/DocumentAttachments.ascx" TagName="DocumentAttachments" TagPrefix="cms" %> <a href="<%# GetDocumentUrl() %>"><%# Eval("Name") %></a><br />

Then select New button next to the Selected item transformation property, again fill any name, select ASCX transformation type and insert the following code:
<%@ Register Src="~/CMSModules/Content/Controls/Attachments/DocumentAttachments/DocumentAttachments.ascx" TagName="DocumentAttachments" TagPrefix="cms" %> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { CMS.SettingsProvider.DataClassInfo dci = CMS.SettingsProvider.DataClassInfoProvider.GetDataClass("custom.customProduct"); string var = CMS.CMSHelper.CMSContext.CurrentDocument.NodeAliasPath; if (dci != null) { FormInfo fi = new FormInfo(dci.ClassFormDefinition); FormFieldInfo ffi = fi.GetFormField("Documents"); Guid AttachmentGroupGUID = ffi.Guid; this.ucAttachments.Path = CMS.DocumentEngine.TreePathUtils.EnsureSingleNodePath(var); this.ucAttachments.AttachmentGroupGUID = AttachmentGroupGUID; this.ucAttachments.TransformationName = "CMS.Root.AttachmentList"; this.ucAttachments.CultureCode = "en-us"; this.ucAttachments.SiteName = "CorporateSite"; this.ucAttachments.ReloadData(true); } } </script> <cms:DocumentAttachments ID="ucAttachments" runat="server" />

Now you should be able to display grouped attachments of the selected document.
-rk-


Applies to: Kentico CMS 7
Share this article on   LinkedIn Google+