upload not working with small files? <4KB?

G

Guest

I stumbled onto silimar posts and think I'm missing something here. I
reviewed the articles listed but am expericing an error when I go over
4KB??? I'm saving to SQl Server 2K, field is image. Nothing set in webconfig,
etc.
Any ideas?

Code:
Dim iLength As Integer = CType(inpFileUp.PostedFile.InputStream.Length,
Integer)
If iLength = 0 Then Exit Sub 'not a valid file
Dim sContentType As String = inpFileUp.PostedFile.ContentType
Dim sFileName As String, i As Integer
Dim bytContent As Byte()
ReDim bytContent(iLength) 'byte array, set to file size


'strip the path off the filename
i = InStrRev(inpFileUp.PostedFile.FileName.Trim, "\")
If i = 0 Then
sFileName = inpFileUp.PostedFile.FileName.Trim
Else
sFileName = Right(inpFileUp.PostedFile.FileName.Trim,
Len(inpFileUp.PostedFile.FileName.Trim) - i)
End If

Try
inpFileUp.PostedFile.InputStream.Read(bytContent, 0, iLength)

Response.Write("filesize = " & iLength & "<br>")

'save new image record
Dim cmdInsert As New SqlCommand
Dim insertstring As String
Dim imageid As String

SqlConnect = New SqlConnection(ConnectString)
SqlConnect.Open()

'add company info
insertstring = "INSERT tblImages ( Image_Name, Image_Filename,
Image_Type, Image_FileSize, Image, DateAdded, AddedBy ) VALUES ( @imagename,
@filename, @contenttype, @filesize, @image, @dateadded, @addedby );SELECT
@@Identity" 'using parameters

cmdInsert = New SqlCommand(insertstring, SqlConnect)

With cmdInsert

.Parameters.Add("@imagename", "" & txtimagetitle.Text)
.Parameters.Add("@filename", "" & sFileName)
.Parameters.Add("@contenttype", "" & sContentType)
.Parameters.Add("@filesize", iLength)
.Parameters.Add("@image", bytContent)
.Parameters.Add("@dateadded", Date.Now())
.Parameters.Add("@addedby", Session("contactid"))

End With

imageid = cmdInsert.ExecuteScalar

'close object and connection
SqlConnect.Close()

'add new item to list
ddexistingimages.Items.Add(New ListItem(txtimagetitle.Text,
imageid))

'set label for status
lblstatus.Text = "Image Saved"

Catch ex As Exception
'Handle your database error here

'set label for status
lblstatus.Text = "Error - Please Contact System Administrator."
'close object and connection
SqlConnect.Close()
End Try
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top