ASPX templates
Version 3.x > ASPX templates > Manually Create a CMSRepeater for files View modes: 
User avatar
Certified Developer 8
Certified Developer 8
bryan-bit-wizards - 11/5/2008 3:03:36 PM
   
Manually Create a CMSRepeater for files
I am attempting to use a manually created CMS Repeater to loop through files uploaded into kentico (images). I would like to display these files dynamically.

Example:

CMS.Controls.CMSRepeater br1 = new CMS.Controls.CMSRepeater();
br1.ClassNames = "CMS.File";
br1.Path = "/Images/folder1/%";
br1.ReloadData(true);
foreach(_______ in br1.Items)
{
<img src="[path to image]">
}

The CMSRepeater gets created and contains "Items". How do I lop through these items to write out the path to image?

Thank you for your help.

-Bryan Soltis

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 11/6/2008 2:51:58 AM
   
RE:Manually Create a CMSRepeater for files
Hi,

You do not need to use the FOREACH statement to get the path to the image. In the transformation used for this repeater you can use some default functions, e.g.:
<%# GetDocumentUrl() %> or
<%# GetImage("ProductPhoto") %> or

you can also create custom function for the transformation - http://www.kentico.com/docs/devguide/adding_custom_functions_to_tra.htm.

I hope it will help.

Besrt Regards,
Juraj Ondrus

User avatar
Certified Developer 8
Certified Developer 8
bryan-bit-wizards - 11/6/2008 7:51:36 AM
   
RE:Manually Create a CMSRepeater for files
Thank you for your response. However, that is not exactly what i need to do. I am not using a transformation in this scenario as it is all being done in the code behind of my page. I am dynamically creating a CMSRepeater in my code behind. I need to loop through its results and write out page content using those files. I need to know how to loop through the Repeaters results and extract the "GetDocumentURL()" value, all from the code behind.

When I create the CMSRepeater object it successfully gets populated with the 3 images in the folder specified.

CMS.Controls.CMSRepeater br1 = new CMS.Controls.CMSRepeater();
br1.ClassNames = "CMS.File";
br1.Path = "/Images/folder1/%";
br1.ReloadData(true);

My issue is I need to loop through those items and write out their specific values.

foreach(item in br1.Items)
{
Response.write (“<img src=” + item.Path + “’>”);
}

My issue is that I’m not sure how to reference the “item” in br1.Items to expose a property that would give me a valid path.

-Bryan

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 11/6/2008 10:09:56 AM
   
RE:Manually Create a CMSRepeater for files
Hello Bryan,

Thank you for your call.

I spoke about your requirement with our developer and CTO. Both of them think your approach is a bit complicated, if you are already doing this by yourself in the code behind.
A simpler way would be to get the needed data also by you.

You can get the specified files (images) the same way as we do it. You can use the SelectNodes method to get the location and properties of images. You can take a look at our code e.g. ~\CMSTemplates\CorporateSiteASPX\ControlsExamples\BasicCalendar.aspx.cs. You can see, how the QueryRepeater is filled in the following file ~\CMSWebParts\Ecommerce\Wishlist.ascx.cs.
In this way you can easily select the required documents, do with them what you want, as you have the whole dataset and display them with the repeater.

I hope this is an acceptable approach for you.

Don't hesitate to ask for more information.

Best Regards,
Boris Pocatko

User avatar
Certified Developer 8
Certified Developer 8
bryan-bit-wizards - 11/6/2008 10:57:48 AM
   
RE:Manually Create a CMSRepeater for files
I was able to reference the files using:

DataSet myDS = TreeHelper.SelectNodes([Path to image]);

if (!DataHelper.DataSourceIsEmpty(myDS))
{
foreach (DataRow mydr in myDS.Tables[0].Rows)
{
litImageFile.Text += "<img src=\"~/CMSPages/GetFile.aspx?nodeguid=" + mydr.ItemArray[13].ToString() + "&maxsidesize=150\">";
}
}


Thank you again for your help!

-Bryan

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 11/6/2008 12:20:46 PM
   
RE:Manually Create a CMSRepeater for files
Hello,

I am glad it helped, GL with the future work :o)

Best Regards,
Boris Pocatko

User avatar
Member
Member
ex_cio-yahoo - 5/3/2009 6:44:04 PM
   
RE:Manually Create a CMSRepeater for files
FYI Boris, all of the Bit-Wizard developers are "Actual Test" certified. It may take some additional coaching.