I have an application that I modified from http://offbeatmammal.com/upload_resize.aspx
Can someone show me how to convert the vbscript UPDATE Query at the end to a DOT NET?????
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ Page Trace="False" Language="vb" aspcompat="true" debug="true" validateRequest="false"%>
<%@ Import Namespace=System.Drawing %>
<%@ Import Namespace=System.Drawing.Imaging %>
<%@ Import Namespace=System %>
<%@ Import Namespace=System.Web %>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE"/>
<meta content="no-cache" http-equiv="pragma" />
<link href="admin.css" rel="stylesheet" type="text/css" />
</head>
<div id="adminnavbar">
<!--#include file="_adminNav.asp"-->
</div>
<h1 style="text-align: center; margin: 0px">Change/Edit Category Image</h1>
<form enctype="multipart/form-data" method="post" runat="server">
<input name="cID" type="hidden" value="<%=Request.Querystring("cat")%>" />
<table style="width: 500px; margin: 10px" cellspacing="15">
<tr><td style="white-space: nowrap">Select the file to upload:</td><td style="text-align: right"><input type="file" name="upload_file1" size="45"></td></tr>
<tr><td>Picture Story</td><td><textarea name="picCaption" rows="2" style="width: 350px"></textarea> </td></tr>
<tr><td colspan=2>Max upload size <%=upload_max_size%>Kb, gif/jpg/png only</td></tr>
<tr><td colspan=2 style="text-align: right"><input type="submit" value="Upload"></td></tr>
</table>
</form>
<SCRIPT LANGUAGE="VBScript" runat="server">
const Lx = 200 ' max width for thumbnails
const Ly = 200 ' max height for thumbnails
const Ox = 600 ' max width for zoom
const Oy = 600 ' max height for zoom
const upload_dir = "../Gallery/" ' directory to upload file
const upload_original = "" ' filename to save original as (suffix added by script)
const upload_thumb = "tn_" ' filename to save thumbnail as (suffix added by script)
const upload_max_size = 3800 ' max size of the upload (KB) note: this doesn't override any server upload limits
dim fileExt ' used to store the file extension (saves finding it multiple times)
dim newWidth, newHeight as integer ' new width/height for the thumbnail
dim L2 ' temp variable used when calculating new size
dim O2
dim fileFld as HTTPPostedFile ' used to grab the file upload from the form
Dim originalimg As System.Drawing.Image ' used to hold the original image
dim msg ' display results
dim upload_ok as boolean ' did the upload work ?
</script>
<%
'randomize() ' used to help the cache-busting on the preview images
upload_ok = false
if lcase(Request.ServerVariables("REQUEST_METHOD"))="post" then
Dim i As Integer
For i = 0 To Request.Files.Count - 1
fileFld = request.files(i)
'fileFld = request.files(0) ' get the first file uploaded from the form (note:- you can use this to itterate through more than one image)
if fileFld.ContentLength > upload_max_size * 1024 then
msg = "Sorry, the image must be less than " & upload_max_size & "Kb"
else
try
originalImg = System.Drawing.Image.FromStream(fileFld.InputStream)
' work out the width/height for the thumbnail. Preserve aspect ratio and honour max width/height
' Note: if the original is smaller than the thumbnail size it will be scaled up
If (originalImg.Width/Lx) > (originalImg.Width/Ly) Then
L2 = originalImg.Width
newWidth = Lx
newHeight = originalImg.Height * (Lx / L2)
if newHeight > Ly then
newWidth = newWidth * (Ly / newHeight)
newHeight = Ly
end if
Else
L2 = originalImg.Height
newHeight = Ly
newWidth = originalImg.Width * (Ly / L2)
if newWidth > Lx then
newHeight = newHeight * (Lx / newWidth)
newWidth = Lx
end if
End If
Dim thumb As New Bitmap(newWidth, newHeight)
'Create a graphics object
Dim gr_dest As Graphics = Graphics.FromImage(thumb)
' just in case it's a transparent GIF force the bg to white
dim sb = new SolidBrush(System.Drawing.Color.White)
gr_dest.FillRectangle(sb, 0, 0, thumb.Width, thumb.Height)
'Re-draw the image to the specified height and width
gr_dest.DrawImage(originalImg, 0, 0, thumb.Width, thumb.Height)
try
'fileExt = System.IO.Path.GetExtension(fileFld.FileName).ToLower()
'originalImg.save(Server.MapPath(upload_dir & upload_original & fileFld.FileName), originalImg.rawformat)
thumb.save(Server.MapPath(upload_dir & upload_thumb & fileFld.FileName), originalImg.rawformat)
'msg = "Uploaded " & fileFld.FileName & " to " & Server.MapPath(upload_dir & upload_original & fileExt)
upload_ok = true
catch
msg = "Sorry, there was a problem saving the thumbnail image."
end try
' Housekeeping for the generated thumbnail
if not thumb is nothing then
thumb.Dispose()
thumb = nothing
end if
If (originalImg.Width/Ox) > (originalImg.Width/Oy) Then
O2 = originalImg.Width
newWidth = Ox
newHeight = originalImg.Height * (Ox / O2)
if newHeight > Oy then
newWidth = newWidth * (Oy / newHeight)
newHeight = Oy
end if
Else
O2 = originalImg.Height
newHeight = Oy
newWidth = originalImg.Width * (Oy / O2)
if newWidth > Ox then
newHeight = newHeight * (Ox / newWidth)
newWidth = Ox
end if
End If
Dim origimg As New Bitmap(newWidth, newHeight)
'Create a graphics object
Dim gr_dest2 As Graphics = Graphics.FromImage(origimg)
' just in case it's a transparent GIF force the bg to white
dim sb2 = new SolidBrush(System.Drawing.Color.White)
gr_dest2.FillRectangle(sb2, 0, 0, origimg.Width, origimg.Height)
'Re-draw the image to the specified height and width
gr_dest2.DrawImage(originalImg, 0, 0, origimg.Width, origimg.Height)
try
'fileExt = System.IO.Path.GetExtension(fileFld.FileName).ToLower()
'originalImg.save(Server.MapPath(upload_dir & upload_original & fileFld.FileName), originalImg.rawformat)
origimg.save(Server.MapPath(upload_dir & fileFld.FileName), originalImg.rawformat)
'msg = "Uploaded " & fileFld.FileName & " to " & Server.MapPath(upload_dir & upload_original & fileExt)
upload_ok = true
catch
msg = "Sorry, there was a problem saving the Large image."
end try
' Housekeeping for the generated thumbnail
if not origimg is nothing then
origimg.Dispose()
origimg = nothing
end if
catch
msg = "Sorry, that was not an image we could process."
end try
end if
' House Keeping !
if not originalImg is nothing then
originalImg.Dispose()
originalImg = nothing
end if
%>
<%
if upload_ok then
Dim picCaption
picCaption=Request.Form("picCaption")
%>
<table>
<tr>
<td valign=top><img src="<%=upload_dir & upload_thumb & fileFld.FileName%>"></td>
<td valign=top style="text-align: left"><%=picCaption%></td>
</tr>
<tr>
<td valign=top colspan="2"><img src="<%=upload_dir & fileFld.FileName%>"></td>
</tr>
</table>
<!--THIS IS MY Classic ASP CODE I NEED TO CONVERT TO DOT NET -->
<%
'INSERT FILE INFO into Database
'Start first insert
Dim sSQL,oConn,picPublish,picSortOrder,cID
Dim picURL AS String
Dim picThumbURL AS String
picURL=upload_dir & fileFld.FileName
picThumbURL=upload_dir & upload_thumb & fileFld.FileName
cID=Request.Form("cID")
%>
<!--#include file="dbconn.asp"-->
<%
sSQL="UPDATE Categories SET catImageURL ='" & picURL & "',catThumbURL ='" & picThumbURL & "',catImageCaption ='" & picCaption & "' WHERE (catID='" & cID & "')"
oConn=Server.CreateObject("ADODB.Connection")
oConn.Open(sDSN)
oConn.Execute(sSQL)
oConn.Close
oConn=Nothing
%>
<meta http-equiv="refresh" content="0;URL=CategoryEditor.asp?cat=<%=cID%>"/>
<%
else
response.write(msg)
end if
%>
<% Next
end if
%>