upload not working with small files? <4KB?

Discussion in 'ASP .Net' started by =?Utf-8?B?Q2hyaXM=?=, Mar 2, 2005.

  1. 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
    =?Utf-8?B?Q2hyaXM=?=, Mar 2, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    456
    =?Utf-8?B?Qg==?=
    Nov 17, 2005
  2. Arthur Connor
    Replies:
    0
    Views:
    370
    Arthur Connor
    Aug 27, 2003
  3. Bryan Bullard

    how to align static struct to a 4kb boundry

    Bryan Bullard, Oct 15, 2003, in forum: C Programming
    Replies:
    1
    Views:
    328
    Mark A. Odell
    Oct 15, 2003
  4. upload large files not working

    , Dec 1, 2005, in forum: ASP General
    Replies:
    10
    Views:
    277
    Kyle Peterson
    Dec 4, 2005
  5. Replies:
    1
    Views:
    85
Loading...

Share This Page