download writes html code to file

Discussion in 'ASP .Net' started by =?Utf-8?B?QUNhdW50ZXI=?=, Jan 10, 2005.

  1. 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
    --
    =?Utf-8?B?QUNhdW50ZXI=?=, Jan 10, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?QUNhdW50ZXI=?=

    Patrice Guest

    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

    --

    "ACaunter" <> a écrit dans le message de
    news:D...
    > 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
    > --
    >
    Patrice, Jan 10, 2005
    #2
    1. Advertising

  3. =?Utf-8?B?QUNhdW50ZXI=?=

    Curt_C [MVP] Guest

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

    --
    Curt Christianson
    Site & Scripts: http://www.Darkfalz.com
    Blog: http://blog.Darkfalz.com


    "ACaunter" <> wrote in message
    news:D...
    > 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
    > --
    >
    Curt_C [MVP], Jan 10, 2005
    #3
  4. 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
    =?Utf-8?B?QUNhdW50ZXI=?=, Jan 11, 2005
    #4
    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. TinyTim
    Replies:
    2
    Views:
    401
    TinyTim
    Aug 10, 2004
  2. Sam --
    Replies:
    2
    Views:
    584
    Sam --
    Mar 17, 2005
  3. Brett  Kelly
    Replies:
    1
    Views:
    651
    Steve C. Orr [MVP, MCSD]
    Jun 16, 2006
  4. Ramon F Herrera
    Replies:
    10
    Views:
    528
    James Kanze
    Jun 4, 2008
  5. TinyTim
    Replies:
    13
    Views:
    223
    Paul Baker [MVP, Windows - SDK]
    Aug 13, 2004
Loading...

Share This Page