

1
using System;
2
3
public 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

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

1
<%@ WebHandler Language="C#" Class="ImageFetch" %>
2
3
using System;
4
using System.Web;
5
using System.Data.SqlClient;
6
using System.Data;
7
using System.IO;
8
9
public 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

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63
