html at end of download - urgent please help!!

Discussion in 'ASP .Net' started by shawn_vandenberg@yahoo.com, Nov 14, 2006.

  1. Guest

    hi there

    i have the following bit of code that downloads/uploads documents from
    a sql database.

    the problem i have is when i download an image for example and look at
    it in notepad i see the binary data and below it the html from the page
    the image was downloaded from. so my 10k image is now 32k.

    please any help would be much appreciated.

    thanks

    shawn



    Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles btnUpload.Click
    Dim iLength As Integer =
    CType(LifeFileUpload.PostedFile.InputStream.Length, Integer)
    If iLength = 0 Then Exit Sub 'not a valid file
    Dim sContentType As String =
    LifeFileUpload.PostedFile.ContentType
    Dim sFileName As String, i As Integer
    Dim bytContent As Byte()
    ReDim bytContent(iLength)

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

    LifeFileUpload.PostedFile.InputStream.Read(bytContent, 0,
    iLength)

    objDonkey.SelectedClient.AddDocument(objDonkey.UserName,
    sFileName, sContentType, iLength, bytContent, "this is a test
    document")


    End Sub

    Protected Sub btnGetDoc_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles btnGetDoc.Click
    Dim DocId As Integer
    Dim objDoc As Life.Clients.Client.DocumentItem

    DocId = HiddenSelectedDoc.Value
    objDonkey.SelectedClient.GetDocuments()
    objDoc = objDonkey.SelectedClient.DocumentList(DocId)


    Response.Buffer = True
    Response.Expires = -1
    Response.ClearContent()
    Response.ClearHeaders()

    Response.ContentType = "image/jpeg" 'objDoc.ContentType

    Response.OutputStream.Write(CType(objDonkey.SelectedClient.GetDocument(DocId),
    Byte()), 0, CInt(objDoc.ContentLegnth))
    Response.AddHeader("Content-Disposition",
    "attachment;filename=" + objDoc.Filename)
    Response.Flush()


    End Sub
     
    , Nov 14, 2006
    #1
    1. Advertising

  2. Guest

    Hi Shawn,

    Try to clear the response object after the following code:

    Response.Buffer = True
    Response.Expires = -1
    Response.ClearContent()
    Response.ClearHeaders()
    // Clear the response object.
    Response.Clear();

    And then when you finished writing into the response stream:

    Response.Flush();
    Response.End();

    I think it might help.

    See ya.

    Thiago Oliveira

    escreveu:

    > hi there
    >
    > i have the following bit of code that downloads/uploads documents from
    > a sql database.
    >
    > the problem i have is when i download an image for example and look at
    > it in notepad i see the binary data and below it the html from the page
    > the image was downloaded from. so my 10k image is now 32k.
    >
    > please any help would be much appreciated.
    >
    > thanks
    >
    > shawn
    >
    >
    >
    > Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles btnUpload.Click
    > Dim iLength As Integer =
    > CType(LifeFileUpload.PostedFile.InputStream.Length, Integer)
    > If iLength = 0 Then Exit Sub 'not a valid file
    > Dim sContentType As String =
    > LifeFileUpload.PostedFile.ContentType
    > Dim sFileName As String, i As Integer
    > Dim bytContent As Byte()
    > ReDim bytContent(iLength)
    >
    > 'strip the path off the filename
    > i = InStrRev(LifeFileUpload.PostedFile.FileName.Trim, "\")
    > If i = 0 Then
    > sFileName = LifeFileUpload.PostedFile.FileName.Trim
    > Else
    > sFileName = Right(LifeFileUpload.PostedFile.FileName.Trim,
    > Len(LifeFileUpload.PostedFile.FileName.Trim) - i)
    > End If
    >
    > LifeFileUpload.PostedFile.InputStream.Read(bytContent, 0,
    > iLength)
    >
    > objDonkey.SelectedClient.AddDocument(objDonkey.UserName,
    > sFileName, sContentType, iLength, bytContent, "this is a test
    > document")
    >
    >
    > End Sub
    >
    > Protected Sub btnGetDoc_Click(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles btnGetDoc.Click
    > Dim DocId As Integer
    > Dim objDoc As Life.Clients.Client.DocumentItem
    >
    > DocId = HiddenSelectedDoc.Value
    > objDonkey.SelectedClient.GetDocuments()
    > objDoc = objDonkey.SelectedClient.DocumentList(DocId)
    >
    >
    > Response.Buffer = True
    > Response.Expires = -1
    > Response.ClearContent()
    > Response.ClearHeaders()
    >
    > Response.ContentType = "image/jpeg" 'objDoc.ContentType
    >
    > Response.OutputStream.Write(CType(objDonkey.SelectedClient.GetDocument(DocId),
    > Byte()), 0, CInt(objDoc.ContentLegnth))
    > Response.AddHeader("Content-Disposition",
    > "attachment;filename=" + objDoc.Filename)
    > Response.Flush()
    >
    >
    > End Sub
     
    , Nov 14, 2006
    #2
    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. Ryan Taylor
    Replies:
    2
    Views:
    960
    Ryan Taylor
    Nov 10, 2004
  2. Guest
    Replies:
    2
    Views:
    4,663
    Guest
    Jan 6, 2006
  3. KK
    Replies:
    2
    Views:
    601
    Big Brian
    Oct 14, 2003
  4. Brett  Kelly
    Replies:
    1
    Views:
    688
    Steve C. Orr [MVP, MCSD]
    Jun 16, 2006
  5. mwschenckCRL
    Replies:
    0
    Views:
    84
    mwschenckCRL
    Oct 27, 2006
Loading...

Share This Page