From: "Bret Thompson" <Bret on
I am attempting to write an ASP page that will download a file rather then
open it, when it is of known type. I found this code here:
http://mosley.arach.net.au/dev/docs/save%20as.htm

The first example works fine, for files under 5 Mb, the second example
downloads the file but the data is corrupted. Using a JGP file as a
reference, it seems to corrupt the end of the file (since the bottom of the
JPEG is corrupted).

Here is the code I am using. Any idea how to fix this? or an alternative
method?


Response.ContentType = "application/x-unknown"
Response.AddHeader "content-disposition","attachment; filename=" &
Request.QueryString("File")

Set adoStream = CreateObject("ADODB.Stream")
chunk = 2048
adoStream.Open()
adoStream.Type = 1
adoStream.LoadFromFile(Server.MapPath(vFilePath))

iSz = adoStream.Size

Response.AddHeader "Content-Length", iSz

For i = 1 To iSz \ chunk
If Not Response.IsClientConnected Then Exit For
Response.BinaryWrite adoStream.Read(chunk)
Next

If iSz Mod chunk > 0 Then
If Response.IsClientConnected Then
Response.BinaryWrite objStream.Read(iSz Mod chunk)
End If
End If

adoStream.Close
Set adoStream = Nothing

Response.End

From: "Ray Costanzo [MVP]" <my first name at lane 34 dot on
What's with the chunks? Perhaps try this code here.

http://www.aspfaq.com/show.asp?id=2161

Ray at work

"Bret Thompson" <Bret Thompson(a)discussions.microsoft.com> wrote in message
news:1737B1C0-6A36-43AC-96D2-72DA752CD128(a)microsoft.com...
> I am attempting to write an ASP page that will download a file rather then
> open it, when it is of known type. I found this code here:
> http://mosley.arach.net.au/dev/docs/save%20as.htm
>
> The first example works fine, for files under 5 Mb, the second example
> downloads the file but the data is corrupted. Using a JGP file as a
> reference, it seems to corrupt the end of the file (since the bottom of
the
> JPEG is corrupted).
>
> Here is the code I am using. Any idea how to fix this? or an alternative
> method?
>
>
> Response.ContentType = "application/x-unknown"
> Response.AddHeader "content-disposition","attachment; filename=" &
> Request.QueryString("File")
>
> Set adoStream = CreateObject("ADODB.Stream")
> chunk = 2048
> adoStream.Open()
> adoStream.Type = 1
> adoStream.LoadFromFile(Server.MapPath(vFilePath))
>
> iSz = adoStream.Size
>
> Response.AddHeader "Content-Length", iSz
>
> For i = 1 To iSz \ chunk
> If Not Response.IsClientConnected Then Exit For
> Response.BinaryWrite adoStream.Read(chunk)
> Next
>
> If iSz Mod chunk > 0 Then
> If Response.IsClientConnected Then
> Response.BinaryWrite objStream.Read(iSz Mod chunk)
> End If
> End If
>
> adoStream.Close
> Set adoStream = Nothing
>
> Response.End
>


From: Bret Thompson on
Ray,

Your link is the exact same code at the correct site. Scroll down to the
part that says
"Many people have complained that larger files simply do not work."
And you will see where I got the code with the "Chunks". This is thier
solution for large files.

The first code example fails with files larger then roughly 5 Mb.

Bret


"Ray Costanzo [MVP]" wrote:

> What's with the chunks? Perhaps try this code here.
>
> http://www.aspfaq.com/show.asp?id=2161
>
> Ray at work
>
> "Bret Thompson" <Bret Thompson(a)discussions.microsoft.com> wrote in message
> news:1737B1C0-6A36-43AC-96D2-72DA752CD128(a)microsoft.com...
> > I am attempting to write an ASP page that will download a file rather then
> > open it, when it is of known type. I found this code here:
> > http://mosley.arach.net.au/dev/docs/save%20as.htm
> >
> > The first example works fine, for files under 5 Mb, the second example
> > downloads the file but the data is corrupted. Using a JGP file as a
> > reference, it seems to corrupt the end of the file (since the bottom of
> the
> > JPEG is corrupted).
> >
> > Here is the code I am using. Any idea how to fix this? or an alternative
> > method?
> >
> >
> > Response.ContentType = "application/x-unknown"
> > Response.AddHeader "content-disposition","attachment; filename=" &
> > Request.QueryString("File")
> >
> > Set adoStream = CreateObject("ADODB.Stream")
> > chunk = 2048
> > adoStream.Open()
> > adoStream.Type = 1
> > adoStream.LoadFromFile(Server.MapPath(vFilePath))
> >
> > iSz = adoStream.Size
> >
> > Response.AddHeader "Content-Length", iSz
> >
> > For i = 1 To iSz \ chunk
> > If Not Response.IsClientConnected Then Exit For
> > Response.BinaryWrite adoStream.Read(chunk)
> > Next
> >
> > If iSz Mod chunk > 0 Then
> > If Response.IsClientConnected Then
> > Response.BinaryWrite objStream.Read(iSz Mod chunk)
> > End If
> > End If
> >
> > adoStream.Close
> > Set adoStream = Nothing
> >
> > Response.End
> >
>
>
>
From: Bret Thompson on
Ray,

Nevermind, I finally found it. There is a typo in thier code. Look at the
2 Response.BinaryWrite statements:
Response.BinaryWrite adoStream.Read(chunk)
Response.BinaryWrite objStream.Read(iSz Mod chunk)

Bret


"Ray Costanzo [MVP]" wrote:

> What's with the chunks? Perhaps try this code here.
>
> http://www.aspfaq.com/show.asp?id=2161
>
> Ray at work
>
> "Bret Thompson" <Bret Thompson(a)discussions.microsoft.com> wrote in message
> news:1737B1C0-6A36-43AC-96D2-72DA752CD128(a)microsoft.com...
> > I am attempting to write an ASP page that will download a file rather then
> > open it, when it is of known type. I found this code here:
> > http://mosley.arach.net.au/dev/docs/save%20as.htm
> >
> > The first example works fine, for files under 5 Mb, the second example
> > downloads the file but the data is corrupted. Using a JGP file as a
> > reference, it seems to corrupt the end of the file (since the bottom of
> the
> > JPEG is corrupted).
> >
> > Here is the code I am using. Any idea how to fix this? or an alternative
> > method?
> >
> >
> > Response.ContentType = "application/x-unknown"
> > Response.AddHeader "content-disposition","attachment; filename=" &
> > Request.QueryString("File")
> >
> > Set adoStream = CreateObject("ADODB.Stream")
> > chunk = 2048
> > adoStream.Open()
> > adoStream.Type = 1
> > adoStream.LoadFromFile(Server.MapPath(vFilePath))
> >
> > iSz = adoStream.Size
> >
> > Response.AddHeader "Content-Length", iSz
> >
> > For i = 1 To iSz \ chunk
> > If Not Response.IsClientConnected Then Exit For
> > Response.BinaryWrite adoStream.Read(chunk)
> > Next
> >
> > If iSz Mod chunk > 0 Then
> > If Response.IsClientConnected Then
> > Response.BinaryWrite objStream.Read(iSz Mod chunk)
> > End If
> > End If
> >
> > adoStream.Close
> > Set adoStream = Nothing
> >
> > Response.End
> >
>
>
>