<%@ Control Language="VB" ClassName="GalleryTable" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<%@ OutputCache Shared="true" Duration="60" VaryByParam="none" %>

<script runat="server">
	'This variable specifies relative path to the folder, where the gallery with uploaded files is located.
	'Do not forget about the slash in the end of the folder name.
	Private _galleryPath As String = "../Gallery/"

	Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
		Dim fileName As String = Server.MapPath(_galleryPath & "Descriptions.xml")
		'Clear cache when Description.xml is changed		
		Me.CachePolicy.Dependency = New CacheDependency(fileName)
	    
		If File.Exists(fileName) Then
			Dim descriptions As New XmlDocument()
			descriptions.Load(fileName)
	        
			If descriptions.DocumentElement.ChildNodes.Count > 0 Then
				DataList1.DataSource = descriptions.DocumentElement.ChildNodes
				DataList1.DataBind()
			End If
		End If
	End Sub

	Private Function EncodeFileName(ByVal value As String) As String
		Return Server.UrlEncode(value).Replace("+", "%20")
	End Function

</script>

<asp:DataList ID="DataList1" Width="100%" RepeatLayout="Table" RepeatDirection="Vertical"
	RepeatColumns="4" runat="server">
	<HeaderTemplate>
	</HeaderTemplate>
	<ItemTemplate>
		<a href="<%# _galleryPath & EncodeFileName(CType(Container.DataItem, XmlElement).GetAttribute("name")) %>"
			target="_blank">
			<img src="<%# _galleryPath & "Thumbnails/" & EncodeFileName(CType(Container.DataItem, XmlElement).GetAttribute("name")) %>.jpg"
				title="<%# Server.HtmlEncode(CType(Container.DataItem, XmlElement).GetAttribute("name"))%>"
				alt="<%# Server.HtmlEncode(CType(Container.DataItem, XmlElement).GetAttribute("name"))%>" />
		</a>
		<br />
		<br />
		<b>Name:</b>
		<%#Server.HtmlEncode(CType(Container.DataItem, XmlElement).GetAttribute("name"))%>
		<br />
		<b>Dimensions:</b>
		<%#Server.HtmlEncode(CType(Container.DataItem, XmlElement).GetAttribute("width"))%>
		x
		<%#Server.HtmlEncode(CType(Container.DataItem, XmlElement).GetAttribute("height"))%>
		<br />
		<b>Description:</b>
		<%#Server.HtmlEncode(CType(Container.DataItem, XmlElement).GetAttribute("description"))%>
	</ItemTemplate>
	<FooterTemplate>
	</FooterTemplate>
</asp:DataList>