I have been assigned to create a web gallery that users can upload to.
Basically. it goes like this
upload image
map paths store on database.
create thumbnail sized image
link thumnmail to larger image.
The issue I am having is that for some reason I am not able to get thumbnail to be uploaded.
so the normal sized images upload just find as does the path.
the thumbnail path uploads fine. but the thumbnail image does not.
I am sure it is just something I have over looked and need a 2nd pair of eyes to see.
here is my code.
=============================
Protected
Sub bt__Upload_Click(ByVal sender
As Object,
ByVal e As System.EventArgs)
Handles bt_UpLoad.Click
' first, check whether a valid full-sized image was uploaded
If FullSizedImage.PostedFile
Is Nothing
Then
'Message.Text = "The full-sized image file does not exist."
Else ' full sized image was uploaded
' just working on the filenames
Dim FilenameAndExtension
As String = System.IO.Path.GetFileName(FullSizedImage.PostedFile.FileName)
Dim IndexOfDot
As Integer = FilenameAndExtension.LastIndexOf(".")
Dim FilenameOnly
As String = FilenameAndExtension.Substring(0, IndexOfDot)
Dim ExtensionOnly
As String = FilenameAndExtension.Substring(IndexOfDot + 1, FilenameAndExtension.Length - IndexOfDot - 1)
Dim ThumbnailFilename
As String = FilenameOnly &
"-t." & ExtensionOnly
' let's save the main image
Dim LocationToSave = Server.MapPath("~/Images/Portfolio/Full/")
Dim Full As
String = "http://exiled-studios.com/images/Portfolio/Full/" & FullSizedImage.FileName &
""
' to start, we'll load up full-sized image as an Image file
' (previously, it was just any old file ... could have been a Word document for all we know)
Dim FullSizePhoto
As System.Drawing.Image
' now that we have it as an image file, we can create a thumbnail easily
' first, we need to be prepared for a problem
Dim dummyCallBack
As System.Drawing.Image.GetThumbnailImageAbort
dummyCallBack =
New System.Drawing.Image.GetThumbnailImageAbort(AddressOf CallBack)
' have gotten ready for a problem, let's create the thumbnail
Dim ThumbnailPhoto
As System.Drawing.Image
Dim Thumb As
String = "http://exiled-studios.com/images/Portfolio/Thumb/" & ThumbnailFilename &
""
' success!
'upload file paaths to database
Dim strConn
As String =
"Server=Server; Database=database; User ID=Username; Password=Password; Integrated Security=False"
Dim MySQL As
String = "Insert into tbl_Gallery(FullPath, ThumbPath, PostedBy, DateSubmitted) " & _
"Values (@FullPath, @ThumbPath, @PostedBy, @DateSubmitted)"
Dim MyConn
As New Data.SqlClient.SqlConnection(strConn)
Dim Cmd As
New Data.SqlClient.SqlCommand(MySQL, MyConn)
With Cmd.Parameters
.Add(
New Data.SqlClient.SqlParameter("@FullPath", Full))
.Add(
New Data.SqlClient.SqlParameter("@ThumbPath", Thumb))
.Add(
New Data.SqlClient.SqlParameter("@PostedBy", User.Identity.Name))
.Add(
New Data.SqlClient.SqlParameter("@DateSubmitted",
Date.Now))
End With
MyConn.Open()
Cmd.ExecuteNonQuery()
MyConn.Close()
MyConn.Dispose()
'Message.Text = "The photo and its thumbnail has been saved."
End If
' was full sized image uploaded?
End Sub
atrum
Member
42 Points
43 Posts
Thumb nail problem.
Mar 08, 2007 02:21 AM|LINK
Hello all,
I have been assigned to create a web gallery that users can upload to.
Basically. it goes like this
upload image
map paths store on database.
create thumbnail sized image
link thumnmail to larger image.
The issue I am having is that for some reason I am not able to get thumbnail to be uploaded.
so the normal sized images upload just find as does the path.
the thumbnail path uploads fine. but the thumbnail image does not.
I am sure it is just something I have over looked and need a 2nd pair of eyes to see.
here is my code.
=============================
Protected
Sub bt__Upload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bt_UpLoad.Click ' first, check whether a valid full-sized image was uploaded If FullSizedImage.PostedFile Is Nothing Then 'Message.Text = "The full-sized image file does not exist." Else ' full sized image was uploaded
' just working on the filenames Dim FilenameAndExtension As String = System.IO.Path.GetFileName(FullSizedImage.PostedFile.FileName) Dim IndexOfDot As Integer = FilenameAndExtension.LastIndexOf(".") Dim FilenameOnly As String = FilenameAndExtension.Substring(0, IndexOfDot) Dim ExtensionOnly As String = FilenameAndExtension.Substring(IndexOfDot + 1, FilenameAndExtension.Length - IndexOfDot - 1) Dim ThumbnailFilename As String = FilenameOnly & "-t." & ExtensionOnly ' let's save the main image Dim LocationToSave = Server.MapPath("~/Images/Portfolio/Full/")FullSizedImage.PostedFile.SaveAs(LocationToSave + FilenameAndExtension)
Dim Full As String = "http://exiled-studios.com/images/Portfolio/Full/" & FullSizedImage.FileName & "" ' to start, we'll load up full-sized image as an Image file ' (previously, it was just any old file ... could have been a Word document for all we know) Dim FullSizePhoto As System.Drawing.ImageFullSizePhoto = System.Drawing.Image.FromFile(LocationToSave + FilenameAndExtension)
' now that we have it as an image file, we can create a thumbnail easily ' first, we need to be prepared for a problem Dim dummyCallBack As System.Drawing.Image.GetThumbnailImageAbortdummyCallBack =
New System.Drawing.Image.GetThumbnailImageAbort(AddressOf CallBack) ' have gotten ready for a problem, let's create the thumbnail Dim ThumbnailPhoto As System.Drawing.ImageThumbnailPhoto = FullSizePhoto.GetThumbnailImage(200, 200, dummyCallBack, IntPtr.Zero)
' release our hold on the full-sized imageFullSizePhoto.Dispose()
' save the thumbnailThumbnailPhoto.Save(LocationToSave + ThumbnailFilename, ImageFormat.Jpeg)
Dim Thumb As String = "http://exiled-studios.com/images/Portfolio/Thumb/" & ThumbnailFilename & "" ' success! 'upload file paaths to database Dim strConn As String = "Server=Server; Database=database; User ID=Username; Password=Password; Integrated Security=False" Dim MySQL As String = "Insert into tbl_Gallery(FullPath, ThumbPath, PostedBy, DateSubmitted) " & _ "Values (@FullPath, @ThumbPath, @PostedBy, @DateSubmitted)" Dim MyConn As New Data.SqlClient.SqlConnection(strConn) Dim Cmd As New Data.SqlClient.SqlCommand(MySQL, MyConn) With Cmd.Parameters.Add(
New Data.SqlClient.SqlParameter("@FullPath", Full)).Add(
New Data.SqlClient.SqlParameter("@ThumbPath", Thumb)).Add(
New Data.SqlClient.SqlParameter("@PostedBy", User.Identity.Name)).Add(
New Data.SqlClient.SqlParameter("@DateSubmitted", Date.Now)) End WithMyConn.Open()
Cmd.ExecuteNonQuery()
MyConn.Close()
MyConn.Dispose()
'Message.Text = "The photo and its thumbnail has been saved." End If ' was full sized image uploaded? End Sub
Public Function CallBack() As Boolean
Return False End Function============================================