Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > html at end of download - urgent please help!!

Reply
Thread Tools

html at end of download - urgent please help!!

 
 
shawn_vandenberg@yahoo.com
Guest
Posts: n/a
 
      11-14-2006
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(bytCont ent, 0,
iLength)

objDonkey.SelectedClient.AddDocument(objDonkey.Use rName,
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.Select edClient.GetDocument(DocId),
Byte()), 0, CInt(objDoc.ContentLegnth))
Response.AddHeader("Content-Disposition",
"attachment;filename=" + objDoc.Filename)
Response.Flush()


End Sub

 
Reply With Quote
 
 
 
 
cmagicos@gmail.com
Guest
Posts: n/a
 
      11-14-2006
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(bytCont ent, 0,
> iLength)
>
> objDonkey.SelectedClient.AddDocument(objDonkey.Use rName,
> 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.Select edClient.GetDocument(DocId),
> Byte()), 0, CInt(objDoc.ContentLegnth))
> Response.AddHeader("Content-Disposition",
> "attachment;filename=" + objDoc.Filename)
> Response.Flush()
>
>
> End Sub


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Direct Download Movies - No Download Limits - Download DivX DVDMovies hussain dandan Python 0 12-06-2009 04:52 AM
Forcing Download of File Appends HTML from Download Page to Downloaded File? Brett Kelly ASP .Net 1 06-16-2006 04:05 AM
File upload/download from database. Download appends aspx page to end of file Ryan Taylor ASP .Net 2 11-10-2004 08:31 PM
is there a difference between CIR and CIR+end to end clear channel connection? ike lozada Cisco 0 05-27-2004 02:34 AM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments