download writes html code to file

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
because you are creating it incorrectly...or streaming it incorrectly.
We'll need some code snippet
 
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
 
Back
Top