download writes html code to file

G

Guest

Hi all,
I was wondering why when i create a text file and download it through my
website, the download will include all the html code for the given page at
the bottom of the text file.

i'm using asp.net
 
P

Patrice

Response.WriteFile (assuming this is what you are using) does nothing else
than inserting the file content in the current output. The page is still
processed as usual and in particular its HTML code is rendered.
Generally a streaming page doesn't have any HTML code as it's sole purpose
is to output the raw content of a file.

Some code may help in case you are not doing things this way.

Patrice
 
C

Curt_C [MVP]

because you are creating it incorrectly...or streaming it incorrectly.
We'll need some code snippet
 
G

Guest

Here is my download code:

Dim iStream As System.IO.Stream = Nothing
Dim buffer(10000) As Byte
Dim length As Integer
Dim dataToRead As Long
Dim filepath As String = x
Dim filename As String = System.IO.Path.GetFileName(filepath)
'Try
iStream = New System.IO.FileStream(filepath,
System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)
dataToRead = iStream.Length
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", "attachment;
filename=" + filename)
While dataToRead > 0
If Response.IsClientConnected Then
length = iStream.Read(buffer, 0, 10000)
Response.OutputStream.Write(buffer, 0, length)
Response.Flush()
buffer(1000) = New Byte
dataToRead = dataToRead - length
Else
dataToRead = -1
End If
End While
'Catch ex As Exception
' Response.Write("Error : " + ex.Message)
'Finally
If Not (iStream Is Nothing) Then
iStream.Close()
End If
 

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

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top