Attachments in transformation

Ilya Buzytsky asked on May 26, 2016 03:02

Hi, in Kentico 9 I want to have two kinds of attachments in products: jpg images and mp3 sound files. Both sets I am going to display on Product Details page via two different Basic Repeater Web Parts. I have several problems and questions:

  1. Below is ASCX transformation I created. I got error 404 - it does not find src images, which I added to Attachments in Properties tab of the product I am testing:

     <li><a href= "<%# GetAbsoluteUrl(GetAttachmentUrl(EvalText("AttachmentName", true), Eval("NodeAliasPath")), EvalInteger("AttachmentSiteID")) %> + ?maxsidesize=960" class="fancyboxProductImg" title="<%# EvalText("AttachmentTitle", true) %>">
       <img src="<%# GetAbsoluteUrl(GetAttachmentUrl(Eval("AttachmentName"), Eval("NodeAliasPath")), EvalInteger("AttachmentSiteID")) %> + ?maxsidesize=46" class="cloudcarousel2d" alt="<%# EvalText("AttachmentTitle", true) %>" title="<%# EvalText("AttachmentDescription", true) %>" /></a></li>
    
  2. In Properties->Attachments I see my two jpg and two mp3 files, but only when I press Edit button. When I press the link itself - I get "The resource you are looking for removed or temporary unavailable". Looks like I missed some step of attachments adding. Did I add them properly? Maybe I have to create two separate new fields, say ProductImages and ProductMP3s? In that case my above transformation should be re-written

  3. If I continue to use Properties->Attachments - how can I differentiate two types of attachments, and really send them to separate Repeaters?

Thanks, Evgeny

Recent Answers


Brenden Kehren answered on May 26, 2016 03:54

Did you take a look at my blog post on Attachments in Page Types and Transformations?

2 votesVote for this answer Mark as a Correct answer

Dennis Hulsmans answered on May 26, 2016 07:59

Evgeny Shtukin

I tried Brendens approach and it's the best solution. Just change this to your own transformation (which will display the download links) ucDocAttachments.TransformationName = "CMS.Root.DocumentAttachments";

This is your field which you configured in your page type to hold the attachments: CMS.FormEngine.FormFieldInfo ffi = fi.GetFormField("Images");

It's really easy once you know it ;).

Thanks a lot for sharing Brenden !

2 votesVote for this answer Mark as a Correct answer

Ilya Buzytsky answered on May 26, 2016 23:11

Brenden - thanks for sharing your great blog. While I am pretty new with Kentico, I tend to agree with your preamble: "Kentico offers so many ways to do similar things which is great, although some of the more beneficial items aren't very well known or easy to find".

Dennis - thank you for your notes. I really don't find in my Kentico 9 installation CMS.Root.DocumentAttachments transformation, so I used CMS.Root.AttachmentList.

But even with new field of Attachments Data Type I have the same problem No.2 from my initial post: I get an error on double-click on the image link in Form tab where I added new images, as well as in the run-time on the site. There is something else I miss in the process of attaching images... Will appreciate any advise. Evgeny

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on May 29, 2016 06:19

It appears with your transformation you're attempting to set specific pieces: a link URL and an image source. If you check out the blog post again, you'll see there is a user control which is actually creating the links and such dynamically without you needing to code them. Here's the full code of the transformation:

<script runat="server">
  protected override void OnInit(EventArgs e)
  {
    CMS.DataEngine.DataClassInfo dci = CMS.DataEngine.DataClassInfoProvider.GetDataClassInfo(Eval("ClassName").ToString(), true);
    if (dci != null)
    {
      CMS.FormEngine.FormInfo fi = new CMS.FormEngine.FormInfo(dci.ClassFormDefinition);
      // field name we added in the page type
      CMS.FormEngine.FormFieldInfo ffi = fi.GetFormField("Images");  
      Guid AttachmentGroupGUID = ffi.Guid;
      ucDocAttachments.Path = Eval<string>("NodeAliasPath");
      ucDocAttachments.AttachmentGroupGUID = AttachmentGroupGUID;
      ucDocAttachments.TransformationName = "CMS.Root.DocumentAttachments";
      ucDocAttachments.ReloadData(true);
    }
  }
</script>

<div class="vehicle">
  <div class="vehicleDescription">  <%# Eval("VehicleType") %></div>
  <div class="lineItem"> <span class="lineDescription">Description:</span> <%# Eval("Description") %>.<br /> </div>
  <div class="lineItem"> <span class="lineDescription">Mileage:</span> <%# Eval("Mileage") %> miles<br /> </div>
  <br/>
  <%# GetAttachmentIcon("AttachmentGUID") %>
<a class="vehiclePhoto" target="_blank" href="<%# GetAbsoluteUrl(GetAttachmentUrl(Eval("AttachmentName"), Eval("NodeAliasPath")), EvalInteger("AttachmentSiteID")) %>">
<%# Eval("AttachmentName",true) %>
  <cms:DocumentAttachments ID="ucDocAttachments" runat="server" /></a>
</div>

Notice that <cms:DocumentAttachments ID="ucDocAttachments" runat="server" /> is in the transformation and also referenced in the <script runat="server"> tag. This step needs to happen to properly bind the control with the attachment data.

0 votesVote for this answer Mark as a Correct answer

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