File Upload control, file loads in VS2008 and server browser, file fails load from client browser across LAN

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


11/18/2008 9:00:42 PM
📃 27051 articles.

💬 1 Replies

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 Then

ClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", "alert ('File has no data. File not uploaded');", True)


ElseIf FileLength > 7168000 Then

ClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", "alert ('File is greater than maximum allowed size of 7 megabytes. File not uploaded.');", True)


End If

Select Case FileContentType

Case "image/pjpeg", "image/jpeg", "image/gif", "image/png"

Case Else

ClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", "alert ('Image formats limited to JPG, GIF, and PNG. File not uploaded.');", True)


End Select

Select Case FileExtension

Case ".jpg", ".gif", ".png"

Case Else

ClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", "alert ('Image formats limited to JPG, GIF, and PNG. File not uploaded.');", True)


End Select

Dim 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


currentUpload.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 Then

thumbWidth = bitmapWidth

thumbHeight = bitmapHeight


thumbWidth = 100

thumbHeight = ((bitmapHeight * 100) / bitmapWidth)

If thumbHeight > 100 Then

thumbWidth = ((bitmapWidth * 100) / bitmapHeight)

thumbHeight = 100

End If

End If

bitmap = DirectCast(bitmap.GetThumbnailImage(thumbWidth, thumbHeight, Nothing, New IntPtr), Bitmap)

bitmap.Save(MemStream, ImageFormat.Jpeg)

Session("DataVB") = MemStream.GetBuffer()




ClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", "alert ('Failed to read file. File not uploaded.');", True)


End Try

End Sub



11/19/2008 7:24:27 PM