<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ImageThumbnail.ascx.cs" Inherits="ImageThumbnail" %>
<asp:Image ID="Image1" runat="server" CssClass="photo" BorderWidth="1" />
<asp:Image ID="Image1" runat="server" CssClass="photo" BorderWidth="1" />
1using System;
2
3public partial class ImageThumbnail : System.Web.UI.UserControl
4{
5 public object PhotoID
6 {
7 get
8 {
9 object o = ViewState["PhotoID"];
10 return (o != null) ? (int)o : 0;
11 }
12 set
13 {
14 ViewState["PhotoID"] = (value != null && value != DBNull.Value) ? Convert.ToInt32(value) : 0;
15 }
16 }
17 public ImageSizes ImageSize
18 {
19 get
20 {
21 object o = ViewState["ImageSize"];
22 return (o != null) ? (ImageSizes)o : ImageSizes.Thumb;
23 }
24 set
25 {
26 ViewState["ImageSize"] = value;
27 }
28 }
29 public enum ImageSizes
30 {
31 Large = 0,
32 Thumb = 1,
33 FullSize = 2
34 }
35 public string NoPhotoImg
36 {
37 get
38 {
39 object o = ViewState["NoPhotoImg"];
40 return (o != null) ? (string)o : null;
41 }
42 set
43 {
44 ViewState["NoPhotoImg"] = value;
45 }
46 }
47 protected void Page_PreRender(object sender, System.EventArgs e)
48 {
49 if (Convert.ToInt32(PhotoID) == 0)
50 {
51 if (NoPhotoImg != null)
52 {
53 Image1.ImageUrl = NoPhotoImg;
54 }
55 else
56 {
57 Image1.Visible = false;
58 }
59 }
60 else
61 {
62 Image1.ImageUrl = "ImageFetch.ashx?Size=" + Convert.ToInt32(ImageSize) + "&ImageID=" + Convert.ToString(PhotoID);
63 }
64 }
65 protected void Page_Load(object sender, EventArgs e)
66 {
67
68 }
69}
70
ImageFetch.ashx
2
3public partial class ImageThumbnail : System.Web.UI.UserControl
4{
5 public object PhotoID
6 {
7 get
8 {
9 object o = ViewState["PhotoID"];
10 return (o != null) ? (int)o : 0;
11 }
12 set
13 {
14 ViewState["PhotoID"] = (value != null && value != DBNull.Value) ? Convert.ToInt32(value) : 0;
15 }
16 }
17 public ImageSizes ImageSize
18 {
19 get
20 {
21 object o = ViewState["ImageSize"];
22 return (o != null) ? (ImageSizes)o : ImageSizes.Thumb;
23 }
24 set
25 {
26 ViewState["ImageSize"] = value;
27 }
28 }
29 public enum ImageSizes
30 {
31 Large = 0,
32 Thumb = 1,
33 FullSize = 2
34 }
35 public string NoPhotoImg
36 {
37 get
38 {
39 object o = ViewState["NoPhotoImg"];
40 return (o != null) ? (string)o : null;
41 }
42 set
43 {
44 ViewState["NoPhotoImg"] = value;
45 }
46 }
47 protected void Page_PreRender(object sender, System.EventArgs e)
48 {
49 if (Convert.ToInt32(PhotoID) == 0)
50 {
51 if (NoPhotoImg != null)
52 {
53 Image1.ImageUrl = NoPhotoImg;
54 }
55 else
56 {
57 Image1.Visible = false;
58 }
59 }
60 else
61 {
62 Image1.ImageUrl = "ImageFetch.ashx?Size=" + Convert.ToInt32(ImageSize) + "&ImageID=" + Convert.ToString(PhotoID);
63 }
64 }
65 protected void Page_Load(object sender, EventArgs e)
66 {
67
68 }
69}
70
1<%@ WebHandler Language="C#" Class="ImageFetch" %>
2
3using System;
4using System.Web;
5using System.Data.SqlClient;
6using System.Data;
7using System.IO;
8
9public class ImageFetch : IHttpHandler
10{
11 const int BUFFERSIZE = 1024;
12
13 public bool IsReusable
14 {
15 get
16 {
17 return true;
18 }
19 }
20
21 public void ProcessRequest(HttpContext context)
22 {
23 HttpResponse response = context.Response;
24 HttpRequest request = context.Request;
25 response.ContentType = "image/jpeg";
26 response.Cache.SetCacheability(HttpCacheability.Public);
27 response.BufferOutput = false;
28 writeSingleImage(Convert.ToInt32(request.QueryString["ImageID"]), Convert.ToInt32(request.QueryString["Size"]), response.OutputStream);
29 response.End();
30 }
31
32 public void writeSingleImage(int ImageID, int size, Stream output)
33 {
34 string cxnstr = System.Configuration.ConfigurationManager.ConnectionStrings["ClubSiteDB"].ConnectionString;
35 SqlConnection connection = new SqlConnection(cxnstr);
36 string query;
37 if (size == 0)
38 {
39 query = "select largeimage from images where id=@item_id";
40 }
41 else if (size == 1)
42 {
43 query = "select thumbimage from images where id=@item_id";
44 }
45 else if (size == 2)
46 {
47 query = "select origimage from images where id=@item_id";
48 }
49 else
50 {
51 query = "select largeimage from images where id=@item_id";
52 }
53 SqlCommand command = new SqlCommand(query, connection);
54 SqlParameter param0 = new SqlParameter("@item_id", SqlDbType.Int);
55 param0.Value = ImageID;
56 command.Parameters.Add(param0);
57 connection.Open();
58
59 byte[] d = ((byte[])(command.ExecuteScalar()));
60 output.Write(d, 0, d.Length);
61 connection.Close();
62 }
63}
2
3using System;
4using System.Web;
5using System.Data.SqlClient;
6using System.Data;
7using System.IO;
8
9public class ImageFetch : IHttpHandler
10{
11 const int BUFFERSIZE = 1024;
12
13 public bool IsReusable
14 {
15 get
16 {
17 return true;
18 }
19 }
20
21 public void ProcessRequest(HttpContext context)
22 {
23 HttpResponse response = context.Response;
24 HttpRequest request = context.Request;
25 response.ContentType = "image/jpeg";
26 response.Cache.SetCacheability(HttpCacheability.Public);
27 response.BufferOutput = false;
28 writeSingleImage(Convert.ToInt32(request.QueryString["ImageID"]), Convert.ToInt32(request.QueryString["Size"]), response.OutputStream);
29 response.End();
30 }
31
32 public void writeSingleImage(int ImageID, int size, Stream output)
33 {
34 string cxnstr = System.Configuration.ConfigurationManager.ConnectionStrings["ClubSiteDB"].ConnectionString;
35 SqlConnection connection = new SqlConnection(cxnstr);
36 string query;
37 if (size == 0)
38 {
39 query = "select largeimage from images where id=@item_id";
40 }
41 else if (size == 1)
42 {
43 query = "select thumbimage from images where id=@item_id";
44 }
45 else if (size == 2)
46 {
47 query = "select origimage from images where id=@item_id";
48 }
49 else
50 {
51 query = "select largeimage from images where id=@item_id";
52 }
53 SqlCommand command = new SqlCommand(query, connection);
54 SqlParameter param0 = new SqlParameter("@item_id", SqlDbType.Int);
55 param0.Value = ImageID;
56 command.Parameters.Add(param0);
57 connection.Open();
58
59 byte[] d = ((byte[])(command.ExecuteScalar()));
60 output.Write(d, 0, d.Length);
61 connection.Close();
62 }
63}