Win2008 Standard with IIS7.0.
VS2008 website project with grid and upload control in form template. File upload control loads image file to database blob column for display by grid.
Using Windows authentication for an intranet application.
Image file uploads to the database blob without errors in VS2008 test environment and from the Win2008 server IE7 browser.
Image file does not upload (falls through to CATCH for file not loaded) when file is selected from client IE7browser on LAN or WAN.
I suspect the problem is then with security setup of IIS 7.0 and/or web.config.
Unable to find specifics of requirements to upload files other than the fileupload control documentation.
Appreciate any insight. Thanks
![]() |
-1 |
![]() |
I used this concept to solve.
Load image file to byte array and check for file size, file content, etc. as needed to verify it is an image file.
Convert byte array to bitmap
Convert bitmap to thumbnail, use any logic you need for this resizing.
Convert bitmap to memory stream and load into session variable (thumbnail might be 13KB or so in size)
Upload session variable into the BLOB column of the database.
Private Sub ManageImageFile(ByVal currentUpload As FileUpload)Dim FileLength As Integer = CInt(currentUpload.PostedFile.InputStream.Length) Dim FileExtension As String = System.IO.Path.GetExtension(currentUpload.PostedFile.FileName).ToLower()Dim FileContentType As String = currentUpload.PostedFile.ContentType.ToLower If FileLength = 0 ThenClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", "alert ('File has no data. File not uploaded');", True) Return ElseIf FileLength > 7168000 ThenClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", "alert ('File is greater than maximum allowed size of 7 megabytes. File not uploaded.');", True) Return End IfSelect Case FileContentType Case "image/pjpeg", "image/jpeg", "image/gif", "image/png" Case ElseClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", "alert ('Image formats limited to JPG, GIF, and PNG. File not uploaded.');", True) Return End SelectSelect Case FileExtension Case ".jpg", ".gif", ".png" Case ElseClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", "alert ('Image formats limited to JPG, GIF, and PNG. File not uploaded.');", True) Return End SelectDim ByteData As Byte() = New Byte(FileLength - 1) {} Dim MemStream As New MemoryStream() Dim bitmapWidth As Integer Dim bitmapHeight As Integer Dim thumbHeight As Integer Dim thumbWidth As Integer TrycurrentUpload.PostedFile.InputStream.Read(ByteData, 0, FileLength)
Dim tc As ComponentModel.TypeConverter = ComponentModel.TypeDescriptor.GetConverter(GetType(Bitmap))Dim bitmap As Bitmap = DirectCast(tc.ConvertFrom(ByteData), Bitmap)bitmapWidth = bitmap.Width
bitmapHeight = bitmap.Height
If bitmapWidth < 100 AndAlso bitmapHeight < 100 ThenthumbWidth = bitmapWidth
thumbHeight = bitmapHeight
ElsethumbWidth = 100
thumbHeight = ((bitmapHeight * 100) / bitmapWidth)
If thumbHeight > 100 ThenthumbWidth = ((bitmapWidth * 100) / bitmapHeight)
thumbHeight = 100
End If End Ifbitmap = DirectCast(bitmap.GetThumbnailImage(thumbWidth, thumbHeight, Nothing, New IntPtr), Bitmap)bitmap.Save(MemStream, ImageFormat.Jpeg)
Session(
"DataVB") = MemStream.GetBuffer()bitmap.Dispose()
MemStream.Close()
CatchClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", "alert ('Failed to read file. File not uploaded.');", True) Return End Try End Sub
![]() |
-1 |
![]() |