ASPX templates
Version 5.x > ASPX templates > Showing document attachments within repeater in an ASPX template View modes: 
User avatar
Member
Member
Erik@amplifystudios.com - 7/20/2010 8:31:46 AM
   
Showing document attachments within repeater in an ASPX template
Hi everyone. We're developing a site for a large hospital network. Within their "Find a Doctor" section they would like to attach documents to each physician and have them listed when the physician's details are displayed. We have set up a "physician" document type, which has a document attachments field for this purpose.

In displaying the physician's details, we're using a repeater within a basic ASPX template. I am attempting to use the DocumentAttachments control/WebPart to display the documents within the repeater, but so far nothing displays. Here is the markup:

<cms:DocumentAttachments ID="ucPhysicianDocs" runat="server"
ZeroRowsText="No documents available."
TransformationName="cms.root.attachment"
Path='<%# Eval("NodeAliasPath") %>' />

I got this example from an "unsorted attachments" page in the KB/FAQ, but it pertained to its use within a transformation, which we would like to avoid in this case (there's just a lot of information being displayed within each repeater item, including videos, etc.). I've tried using "DocumentAttachments.ascx" within the CMSInlineControls and CMSWebParts folders, but to no avail.

I believe "NodeAliasPath" may be the issue, since I don't think the documents are being stored within the same folder as the "physician" documents. In fact, I cannot find them anywhere, so I'm not sure this is the right way to display them. Ideas?

Erik

User avatar
Member
Member
Erik@amplifystudios.com - 7/20/2010 2:48:29 PM
   
RE:Showing document attachments within repeater in an ASPX template
I got a little farther, to the point where I'm displaying the attachments, but I had to add the AttachmentGroupGUID attribute, like so:

<cms:DocumentAttachments ID="ucPhysicianDocs" runat="server"
ZeroRowsText="No documents available."
TransformationName="cms.root.attachment"
AttachmentGroupGUID="5EAAFAE9-EA38-47C1-8D0E-6EFC1362220D" />

I also was able to take out the Path attribute, since the attachments aren't really stored in the tree (right?).

While I have things working fine now, I'm not too keen on having to go into the database to get the AttachmentGroupGUID value. I couldn't see it anywhere within the CMSDesk or CMSSiteManager GUI, so I looked in the DB and found it within the CMSAttachments table (I had to add a document attachment before I could pull the value, though). Is there a better way to retrieve this GUID?

Erik

User avatar
Kentico Consulting
Kentico Consulting
kentico_mirekr - 7/23/2010 8:31:21 AM
   
RE:Showing document attachments within repeater in an ASPX template
Hi,

You can use following example code in your transformation to get AttachmentGroupGUID of your document type field in transformation and you would also need to reload the document attachment control then. Example:

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{

CMS.SettingsProvider.DataClassInfo dci = CMS.SettingsProvider.DataClassInfoProvider.GetDataClass("cms.news");

if (dci != null)
{
CMS.FormEngine.FormInfo fi = new CMS.FormEngine.FormInfo(dci.ClassFormDefinition);
CMS.FormEngine.FormFieldInfo ffi = fi.GetFormField("NewsAttachments");
Guid AttachmentGroupGUID = ffi.Guid;

this.ucPhysicianDocs.AttachmentGroupGUID = AttachmentGroupGUID;
this.ucPhysicianDocs.CultureCode = CMSContext.CurrentDocumentCulture.CultureCode;
this.ucPhysicianDocs.SiteName = CMSContext.CurrentSiteName;
this.ucPhysicianDocs.ReloadData(true);
}
}

</script>


Document attachments are part of the documents so you need to point Path property of the DocumentAttachments control to specific document from which you would like to display its attachments. If Path property is not set, current document node alias pnath it used.

I hope this will help you.

Best regards,
Miroslav Remias.

User avatar
Member
Member
andreycoman-yahoo - 11/18/2011 9:43:52 AM
   
RE:Showing document attachments within repeater in an ASPX template
Hi Miroslav,

I've created a custom Document type in Kentico 6 and I want to show documents attachments within a repeater but only thing that I get is a div element with Pager class.
I followed up http://devnet.kentico.com/docs/6_0/devguide/index.html?handling_attachments_in_transformations.htm

This is the transformation for documents (which it works well):

<%@ Register Src="~/CMSInlineControls/DocumentAttachments.ascx" TagName="DocumentAttachments" TagPrefix="cms" %>
<article>
<div class="article-teaser">
<img alt="cover placeholder" src="<%# GetFileUrl("ThumbnailImage") %>" />
<h2><%# Eval("Title") %></h2>
<ul>
<cms:DocumentAttachments ID="ucDocAttachments" runat="server" TransformationName="custom.PrintMaterial.Attachments" Path='<%# Eval("/Other-Resources/Print-Materials") %>' />
</ul>
</div>
</article>


With following transformation (custom.PrintMaterial.Attachments) I want to put all attachments into a list:


<li>
<a target="_blank" href="<%# GetAbsoluteUrl(GetAttachmentUrl(Eval("AttachmentName"), Eval("/Other-Resources/Print-Materials")), EvalInteger("AttachmentSiteID")) %>">
<%# Eval("AttachmentName",true) %>
</a>
</li>


can you please tell me what I'm doing wrong? What I'm trying is to show all the documents, each one with a list of his attachments...

Thanks,
Andrei

User avatar
Kentico Consulting
Kentico Consulting
kentico_mirekr - 11/21/2011 5:36:30 AM
   
RE:Showing document attachments within repeater in an ASPX template
Hi,

I hope that you know that there are several types of document attachments:

http://devnet.kentico.com/docs/6_0/devguide/attachments_overview.htm

With the approach that you are currently using you can display/list only unsorted attachments as it is stated at the beginning of the documentation you are referring to. If you would follow my example from previous reply in this thread, you would be able to display grouped attachments.

Thanks,
Miro

User avatar
Member
Member
andreycoman-yahoo - 11/22/2011 7:32:48 AM
   
RE:Showing document attachments within repeater in an ASPX template
Hi,

Thank you for your response. So to display using a repeater a list of grouped attachments for each document I have to add Document attachments web part next to repeater webpart, but I'm a little confused on where to put your example code.(in repeater transformation?) Now I can see the attachment but only on each document page.
Can you please provide me a short list of steps to transform my transformation to work with grouped attachments?
If I try to do like Erik in his first post I received a lot of errors...

Thanks,
Andrei

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 11/23/2011 8:48:44 AM
   
RE:Showing document attachments within repeater in an ASPX template
Hi,

you need to use "nested approach" in case you would like to display attachments in a preview transformation of repeater. You need to insert following code into appropriate transformation of your repeater:


<%@ Register Src="~/CMSModules/Content/Controls/Attachments/DocumentAttachments/DocumentAttachments.ascx" TagName="DocumentAttachments" TagPrefix="cms" %>

<cms:DocumentAttachments ID="documentAttachments" runat="server" TransformationName="CMS.Root.AttachmentList" Path='<%# Eval("NodeAliasPath") %>' AttachmentGroupGUID="eac7f820-b2c4-4328-88bd-133660d74338" />


Please note that you need to specify AttachmentGroupGuid which you can find in CMS_Attachment table.

This way you should be able to display list of documents with their unsorted document attachments.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
andreycoman-yahoo - 11/24/2011 3:07:05 AM
   
RE:Showing document attachments within repeater in an ASPX template

Thanks Ivana,

It works very well.

Best regards,
Andrei

User avatar
Member
Member
lwhittemore-emh - 2/25/2014 4:50:58 PM
   
RE:Showing document attachments within repeater in an ASPX template
Is it possible to get the attachments for a document on another site? (same kentico installation)

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 2/27/2014 1:19:43 AM
   
RE:Showing document attachments within repeater in an ASPX template
Hi,

Yes, it is possible using the API mentioned above - you will just need to set the other site ID or name when getting the attachments eventually use the API to get the documents from other site and then access the document attachments. It is up to you what IDs you will set in the code - they can be from other site too.

Best regards,
Juraj Ondrus