Create thumbnail after insert

Tips submitted by ASP.NET Maker users

Create thumbnail after insert

Postby ribaraki » Tue Aug 18, 2009 2:16 pm

replace after insert server side event, make sure to change your field foto1 in recordset, also make sure you have thumbs folder created.

Public Sub Row_Inserted(rs As OrderedDictionary)
'HttpContext.Current.Response.Write("Row Inserted")

Dim objImage, objThumbnail As System.Drawing.Image
Dim strServerPath, strFilename As String
Dim shtWidth, shtHeight As Short
shtWidth = 100

' Get image folder path on server - use "\" string if root
strServerPath = System.Web.HttpContext.Current.Server.MapPath("App_Upload\fotos\")

' Retrieve name of file to resize from query string
strFilename = strServerPath & rs("foto1")

' Retrieve file, or error.gif if not available
objImage = System.Drawing.Image.FromFile(strFilename)
objImage = System.Drawing.Image.FromFile(strServerPath & "error.gif")
End Try

' Work out a proportionate height from width
shtHeight = objImage.Height / (objImage.Width / shtWidth)

' Create thumbnail
objThumbnail = objImage.GetThumbnailImage(shtWidth, _
shtHeight, Nothing, System.IntPtr.Zero)

' Send down to client
'Response.ContentType = "image/jpeg"
objThumbnail.Save(System.Web.HttpContext.Current.Server.MapPath("App_Upload\thumbs\") & rs("foto1"), System.Drawing.Imaging.ImageFormat.Jpeg)

' Tidy up

'Dim sUpdateSql As String = "UPDATE MyTable SET Field1=Value1, Field2=Value2, Field3=Value3 WHERE MyField=XXX"
End Sub

Return to User Submited Tips (ASP.NET Maker)