-
Notifications
You must be signed in to change notification settings - Fork 4
/
DownloadPhoto.ashx.vb
executable file
·85 lines (54 loc) · 2.51 KB
/
DownloadPhoto.ashx.vb
1
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
Imports System.Web
Imports System.Web.Services
Imports DotNetNuke.Common
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Entities.Portals
Namespace Ventrian.SimpleGallery
Public Class DownloadPhoto
Implements System.Web.IHttpHandler
#Region " Private Members "
Private _photoID As Integer = Null.NullInteger
#End Region
#Region " Private Methods "
Private Sub ReadQueryString(ByVal context As HttpContext)
If Not (context.Request("PhotoID") Is Nothing) Then
If (IsNumeric(context.Request("PhotoID"))) Then
_photoID = Convert.ToInt32(context.Request("PhotoID"))
End If
End If
End Sub
#End Region
#Region " Properties "
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
#End Region
#Region " Event Handlers "
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Try
context.Items.Add("httpcompress.attemptedinstall", "true")
ReadQueryString(context)
If (_photoID <> Null.NullInteger) Then
Dim objPhotoController As New Ventrian.SimpleGallery.Entities.PhotoController
Dim objPhoto As Ventrian.SimpleGallery.Entities.PhotoInfo = objPhotoController.Get(_photoID)
If (objPhoto IsNot Nothing) Then
Dim filePath As String = context.Server.MapPath(PortalSettings.Current.HomeDirectory & objPhoto.HomeDirectory & "/" & objPhoto.FileName)
Dim fileInfo As System.IO.FileInfo = New System.IO.FileInfo(filePath)
context.Response.Clear()
context.Response.AddHeader("Content-Disposition", "attachment;filename=" + context.Server.UrlEncode(fileInfo.Name))
context.Response.AddHeader("Content-Length", fileInfo.Length.ToString())
context.Response.ContentType = "image/jpeg"
context.Response.WriteFile(fileInfo.FullName)
context.Response.Flush()
context.Response.End()
End If
End If
Catch ex As Exception
Throw
End Try
End Sub
#End Region
End Class
End Namespace