I had no problem uploading an image to MSSQL and then retrieving/displaying it.
Now I need to be able to resize it before I upload it. Here is what I currently have, but I can't get it to display after upload, so I'm sure I'm doing something wrong.
<code>
If Not filMyFile.PostedFile Is Nothing Then
' Get a reference to PostedFile object
Dim myFile As HttpPostedFile = filMyFile.PostedFile
Dim objImage As System.Drawing.Image = System.Drawing.Image.FromStream(myFile.InputStream)
Dim newImage As System.Drawing.Image = objImage.GetThumbnailImage(150, 150, Nothing, New System.IntPtr())
Dim io As New MemoryStream()
newImage.Save(io, System.Drawing.Imaging.ImageFormat.Jpeg)
' Get size of uploaded file
Dim nFileLen As Integer = io.Length
' make sure the size of the file is > 0
If nFileLen > 0 Then
' Allocate a buffer for reading of the file
Dim myData(nFileLen) As Byte
' Read uploaded file from the Stream
io.Read(myData, 0, nFileLen)
' Create a name for the file to store
Dim strFilename As String = Path.GetFileName(myFile.FileName)
' Store it in database
Dim nFileID As Integer = WriteToDB(strFilename, myFile.ContentType, myData)
' Set label's text
lblInfo.Font.Size = lblInfo.Font.Size.XXSmall
lblInfo.ForeColor = lblInfo.ForeColor.Green
lblInfo.Text = "Filename: " & strFilename & "<br>" & "Size: " & nFileLen.ToString() & "<p>"
lblInfo.Visible = True
imgDB.ToolTip = "This file was stored in database."
' show the images and text
imgDB.ImageUrl = "associatemonthpicture.aspx?FileID=" + nFileID.ToString()
imgDB.Visible = True
End If
End If
</code>
Now I need to be able to resize it before I upload it. Here is what I currently have, but I can't get it to display after upload, so I'm sure I'm doing something wrong.
<code>
If Not filMyFile.PostedFile Is Nothing Then
' Get a reference to PostedFile object
Dim myFile As HttpPostedFile = filMyFile.PostedFile
Dim objImage As System.Drawing.Image = System.Drawing.Image.FromStream(myFile.InputStream)
Dim newImage As System.Drawing.Image = objImage.GetThumbnailImage(150, 150, Nothing, New System.IntPtr())
Dim io As New MemoryStream()
newImage.Save(io, System.Drawing.Imaging.ImageFormat.Jpeg)
' Get size of uploaded file
Dim nFileLen As Integer = io.Length
' make sure the size of the file is > 0
If nFileLen > 0 Then
' Allocate a buffer for reading of the file
Dim myData(nFileLen) As Byte
' Read uploaded file from the Stream
io.Read(myData, 0, nFileLen)
' Create a name for the file to store
Dim strFilename As String = Path.GetFileName(myFile.FileName)
' Store it in database
Dim nFileID As Integer = WriteToDB(strFilename, myFile.ContentType, myData)
' Set label's text
lblInfo.Font.Size = lblInfo.Font.Size.XXSmall
lblInfo.ForeColor = lblInfo.ForeColor.Green
lblInfo.Text = "Filename: " & strFilename & "<br>" & "Size: " & nFileLen.ToString() & "<p>"
lblInfo.Visible = True
imgDB.ToolTip = "This file was stored in database."
' show the images and text
imgDB.ImageUrl = "associatemonthpicture.aspx?FileID=" + nFileID.ToString()
imgDB.Visible = True
End If
End If
</code>