Http Handler:
<%@ WebHandler Language="C#" Class="ShowImage" %>
using System;
using System.Web;
public class ShowImage : IHttpHandler {
public void ProcessRequest (HttpContext context) {
Int32 theID;
if (context.Request.QueryString["id"] != null)
theID = Convert.ToInt32(context.Request.QueryString["id"]);
else
throw new ArgumentException("No parameter specified");
context.Response.ContentType = "image/jpeg";
System.IO.Stream strm = DisplayImage(theID);
byte[] buffer = new byte[2048];
int byteSeq = strm.Read(buffer, 0, 2048);
while (byteSeq > 0)
{
context.Response.OutputStream.Write(buffer, 0, byteSeq);
byteSeq = strm.Read(buffer, 0, 2048);
}
}
public System.IO.Stream DisplayImage(int theID)
{
string cs = System.Configuration.ConfigurationManager.ConnectionStrings["TempConnectionString"].ConnectionString;
using (System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(cs))
{
string sql = "SELECT g_images FROM tblImage WHERE id = @ID";
using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sql, connection))
{
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.AddWithValue("@ID", theID);
connection.Open();
object theImg = cmd.ExecuteScalar();
try
{
return new System.IO.MemoryStream((byte[])theImg);
}
catch
{
return null;
}
finally
{
cmd.Dispose();
connection.Close();
connection.Dispose();
}
}
}
}
public bool IsReusable {
get {
return false;
}
}
}
Slide Show Page(Code Behind):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using COSTACCLib;
using System.Data;
public partial class Gallery : CustomBasePage
{
public static string comCode;
public static string proCode;
CAProcessAccess ImageProc = new CAProcessAccess("master");
protected void Page_Load(object sender, EventArgs e)
{
comCode = txtComCode.Text;
proCode = txtProCode.Text;
}
protected void btnShowGallery_Click(object sender, EventArgs e)
{
Image1.Visible = true;
prevButton.Visible = true;
playButton.Visible = true;
nextButton.Visible = true;
}
[System.Web.Services.WebMethodAttribute()]
[System.Web.Script.Services.ScriptMethodAttribute()]
public static AjaxControlToolkit.Slide[] GetSlides()
{
CAProcessAccess ImageProc = new CAProcessAccess("master");
DataSet ds = ImageProc.GetRecords("", "SP_Gallery_Image", "GETID", comCode, proCode, "", "");
DataTable dt = ds.Tables[0];
AjaxControlToolkit.Slide[] slides = new AjaxControlToolkit.Slide[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
int imgID = Convert.ToInt32(dt.Rows[i]["ID"]);
slides[i] = new AjaxControlToolkit.Slide("ShowImage.ashx?ID=" + imgID, "test", "test");
}
return slides;
}
}
Slide Show Page:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Gallery.aspx.cs" Inherits="Gallery" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>
<script type="text/javascript">
function pageLoad() {
var slide = $find('SSBehaviorID');
if (slide != null) {
slide.add_slideChanging(animateSlides);
var ae = $find("ae");
var be = ae.get_OnLoadBehavior();
var an = be.get_animation();
fadein = an.get_animations()[1];
fadeout = an.get_animations()[0];
fadein.set_duration(1.0);
fadeout.set_duration(1.0);
}
}
function animateSlides() {
fadein.play();
window.setTimeout("fadeout.play()", 2000);
}
</script>
<div style="text-align:center;">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:Label ID="lblComCode" runat="server" Font-Bold="True" Text="Company Code:"></asp:Label>
<asp:TextBox ID="txtComCode" runat="server"></asp:TextBox>
<asp:Label ID="lblProCode" runat="server" Font-Bold="True"
Text="Project Code: "></asp:Label>
<asp:TextBox ID="txtProCode" runat="server"></asp:TextBox>
<asp:Button ID="btnShowGallery" runat="server" onclick="btnShowGallery_Click"
Text="Show" />
<br />
<br />
<asp:Label runat="Server" ID="imageTitle" CssClass="slideTitle"/><br />
<asp:Image ID="Image1" runat="server"
Height="400px" Width="600px" Visible="false"
Style="border: 1px solid black;"
AlternateText="There is no image for this project..."
/>
<br />
<asp:Label runat="server" ID="imageDescription" CssClass="slideDescription"></asp:Label>
<br />
<br />
<asp:Button runat="Server" ID="prevButton" Text="Prev" Font-Size="Larger" Visible="false" />
<asp:Button runat="Server" ID="playButton" Text="Play" Font-Size="Larger" Visible="false" />
<asp:Button runat="Server" ID="nextButton" Text="Next" Font-Size="Larger" Visible="false" />
<ajaxToolkit:SlideShowExtender ID="slideshowextend1" runat="server"
TargetControlID="Image1"
SlideShowServiceMethod="GetSlides"
BehaviorID="SSBehaviorID"
AutoPlay="true"
ImageTitleLabelID="imageTitle"
ImageDescriptionLabelID="imageDescription"
NextButtonID="nextButton"
PlayButtonText="Play"
StopButtonText="Stop"
PreviousButtonID="prevButton"
PlayButtonID="playButton"
Loop="true"
SlideShowAnimationType="Rotate" />
<ajaxToolkit:AnimationExtender ID="animationextend1" runat="server" BehaviorID="ae" TargetControlID="Image1">
<Animations>
<OnLoad>
<Sequence>
<FadeOut Duration="0" Fps="20" />
<FadeIn Duration="0" Fps="20" />
</Sequence>
</OnLoad>
</Animations>
</ajaxToolkit:AnimationExtender>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnShowGallery" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</asp:Content>
I give you the raw code of mine and I think you can get the idea from that...