Use the AjaxSlideShowExtender to show pictures in a directory
The AjaxSlideShowExtender will automatically display a slide show in an image control. The slide show extender calls a shared function to get a list of slides. This tip shows hows to create slide of all the images in a folder.
The Pages HTML
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<div style="text-align: center">
<asp:Image ID="Image1" runat="server" Height="300" Style="border: 1px solid black;
width: auto" ImageUrl="images/ajax.jpg"
AlternateText="Ajax" />
<asp:Label runat="Server" ID="imageLabel1" /><br />
<br />
<asp:Button runat="Server" ID="prevButton" Text="Prev" Font-Size="Larger" />
<asp:Button runat="Server" ID="playButton" Text="Play" Font-Size="Larger" />
<asp:Button runat="Server" ID="nextButton" Text="Next" Font-Size="Larger" />
<ajaxToolkit:SlideShowExtender ID="slideshowextend1" runat="server" TargetControlID="Image1"
SlideShowServiceMethod="GetPictures" AutoPlay="true" ImageDescriptionLabelID="imageLabel1"
NextButtonID="nextButton" PlayButtonText="Play" StopButtonText="Stop" PreviousButtonID="prevButton"
PlayButtonID="playButton" Loop="true" />
<asp:Label ID="lblError" runat="server" />
</div>
</div>
</form>
</body>
</html>
The Code Behind File
Imports System.IO
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MyData.ImagePath = Server.MapPath("~/Images")
Dim strUrl As String = Request.Url.ToString
MyData.Url = strUrl.Substring(0, strUrl.LastIndexOf("/")) & "/Images/"
End Sub
<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
Public Shared Function GetPictures() As AjaxControlToolkit.Slide()
Dim di As New DirectoryInfo(MyData.ImagePath)
Dim s(di.GetFiles.Length - 1) As AjaxControlToolkit.Slide
Dim x As Integer = 0
For Each fi As FileInfo In di.GetFiles()
s(x) = New AjaxControlToolkit.Slide(MyData.Url & fi.Name, "", Path.GetFileNameWithoutExtension(fi.Name))
x += 1
Next
Return s
End Function
End Class
Public Class MyData
Private Shared _Path As String
Private Shared _Url As String
Public Shared Property ImagePath() As String
Get
Return _Path
End Get
Set(ByVal value As String)
_Path = value
End Set
End Property
Public Shared Property Url() As String
Get
Return _Url
End Get
Set(ByVal value As String)
_Url = value
End Set
End Property
End Class