html at end of download - urgent please help!!

S

shawn_vandenberg

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
 
C

cmagicos

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

(e-mail address removed) escreveu:
 

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,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top