Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: Re: File Download Dialog Box


Message #1 by "cindy zhou" <czhou@w...> on Thu, 5 Sep 2002 15:38:55
Hello,Anoop:

I want clients to download files from my web server. Files are in 
different formats.As you suggested, I read the article in 
http://www.aspalliance.com/nothingmn/Default.asp?aid=2 
I can download files in pdf, txt format successfully. Excel and Word
files can be downloaded, but the content is messed up ( I mean there are 
sth like binary code along with the original message). Do you or anyone 
else have any idea of what problem it could be. I attached my code in the 
following. Thanks.
---From Cindy


Response.contenttype="application/vnd.ms-excel" 
Response.AddHeader "content-
disposition", "attachment;filename=CustReport.xls"
Response.BinaryWrite getBinaryFile(server.mappath("CustReport.xls")) 

function getBinaryFile(fileSpec) 
   Dim adTypeBinary
   adTypeBinary = 1 
   Dim oStream 
   set oStream = server.createobject("ADODB.Stream") 
   oStream.Open 
   oStream.Type = adTypeBinary 
   oStream.LoadFromFile fileSpec 
   getBinaryFile= oStream.read 
   set oStream=nothing 
end function 



Message #2 by Imar Spaanjaars <Imar@S...> on Thu, 05 Sep 2002 16:37:37 +0200
Are you sure you are not sending ANY other content to the page as well? No 
spaces, no HTML content / comments etc etc??

Try a Response.Clear right before the call to BinaryWrite.

HtH

Imar


At 03:38 PM 9/5/2002 +0000, you wrote:
>Hello,Anoop:
>
>I want clients to download files from my web server. Files are in
>different formats.As you suggested, I read the article in
>http://www.aspalliance.com/nothingmn/Default.asp?aid=2
>I can download files in pdf, txt format successfully. Excel and Word
>files can be downloaded, but the content is messed up ( I mean there are
>sth like binary code along with the original message). Do you or anyone
>else have any idea of what problem it could be. I attached my code in the
>following. Thanks.
>---From Cindy
>
>
>Response.contenttype="application/vnd.ms-excel"
>Response.AddHeader "content-
>disposition", "attachment;filename=CustReport.xls"
>Response.BinaryWrite getBinaryFile(server.mappath("CustReport.xls"))
>
>function getBinaryFile(fileSpec)
>    Dim adTypeBinary
>    adTypeBinary = 1
>    Dim oStream
>    set oStream = server.createobject("ADODB.Stream")
>    oStream.Open
>    oStream.Type = adTypeBinary
>    oStream.LoadFromFile fileSpec
>    getBinaryFile= oStream.read
>    set oStream=nothing
>end function


Message #3 by "Daniel Watts" <danielwatts@c...> on Thu, 5 Sep 2002 15:47:19 +0100
When you uploaded them did you use the right mode (Binary/Ascii)?
Maybe word docs need to be uploaded in binary?

Dan

-----Original Message-----
From: bounce-asp_web_howto-1177368@p...
[mailto:bounce-asp_web_howto-1177368@p...]On Behalf Of cindy
zhou
Sent: Thursday 05 September 2002 15:39
To: ASP Web HowTo
Subject: [asp_web_howto] Re: File Download Dialog Box


Hello,Anoop:

I want clients to download files from my web server. Files are in
different formats.As you suggested, I read the article in
http://www.aspalliance.com/nothingmn/Default.asp?aid=2
I can download files in pdf, txt format successfully. Excel and Word
files can be downloaded, but the content is messed up ( I mean there are
sth like binary code along with the original message). Do you or anyone
else have any idea of what problem it could be. I attached my code in the
following. Thanks.
---From Cindy


Response.contenttype="application/vnd.ms-excel"
Response.AddHeader "content-
disposition", "attachment;filename=CustReport.xls"
Response.BinaryWrite getBinaryFile(server.mappath("CustReport.xls"))

function getBinaryFile(fileSpec)
   Dim adTypeBinary
   adTypeBinary = 1
   Dim oStream
   set oStream = server.createobject("ADODB.Stream")
   oStream.Open
   oStream.Type = adTypeBinary
   oStream.LoadFromFile fileSpec
   getBinaryFile= oStream.read
   set oStream=nothing
end function




---

Improve your web design skills with these new books from Glasshaus.

Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
r-20

Message #4 by "cindy zhou" <czhou@w...> on Thu, 5 Sep 2002 16:00:54
Thank you, Imar.

With your suggestion, it works now.

Cindy



> Are you sure you are not sending ANY other content to the page as well? 
No 
spaces, no HTML content / comments etc etc??

Try a Response.Clear right before the call to BinaryWrite.

HtH

Imar


At 03:38 PM 9/5/2002 +0000, you wrote:
>Hello,Anoop:
>
>I want clients to download files from my web server. Files are in
>different formats.As you suggested, I read the article in
>http://www.aspalliance.com/nothingmn/Default.asp?aid=2
>I can download files in pdf, txt format successfully. Excel and Word
>files can be downloaded, but the content is messed up ( I mean there are
>sth like binary code along with the original message). Do you or anyone
>else have any idea of what problem it could be. I attached my code in the
>following. Thanks.
>---From Cindy
>
>
>Response.contenttype="application/vnd.ms-excel"
>Response.AddHeader "content-
>disposition", "attachment;filename=CustReport.xls"
>Response.BinaryWrite getBinaryFile(server.mappath("CustReport.xls"))
>
>function getBinaryFile(fileSpec)
>    Dim adTypeBinary
>    adTypeBinary = 1
>    Dim oStream
>    set oStream = server.createobject("ADODB.Stream")
>    oStream.Open
>    oStream.Type = adTypeBinary
>    oStream.LoadFromFile fileSpec
>    getBinaryFile= oStream.read
>    set oStream=nothing
>end function


Message #5 by jeff.montgomery@m... on Thu, 12 Sep 2002 05:25:33
I have not used the methods you are using, but I had a problem that sounds 
similar, and maybe it's what's happening you your file. I found that the 
FileSystemObject.ReadAll function does not interpret certain characters 
correctly such as nulls, and was ruining my files (they were also Excel 
files). I had to use the Read method in a loop instead, reading one byte 
at a time. For some reason this worked and did not fail on nulls or other 
characters. Perhaps there is a similar limitation in the method you are 
calling.

Also, I don't think that "application/vnd.ms-excel" is the correct MIME 
type for an Excel file. Do you have a reason for using this type?

Lastly, we use a third-party component, Infomentum's ActiveFile, for file 
upload and download. The API takes some getting used to, but if you follow 
the technical details and their samples, it will work.

Jeff Montgomery
jeff.montgomery@m...


> Hello,Anoop:

> I want clients to download files from my web server. Files are in 
d> ifferent formats.As you suggested, I read the article in 
h> ttp://www.aspalliance.com/nothingmn/Default.asp?aid=2 
I>  can download files in pdf, txt format successfully. Excel and Word
f> iles can be downloaded, but the content is messed up ( I mean there are 
s> th like binary code along with the original message). Do you or anyone 
e> lse have any idea of what problem it could be. I attached my code in 
the 
f> ollowing. Thanks.
-> --From Cindy

> 
R> esponse.contenttype="application/vnd.ms-excel" 
R> esponse.AddHeader "content-
d> isposition", "attachment;filename=CustReport.xls"
R> esponse.BinaryWrite getBinaryFile(server.mappath("CustReport.xls")) 

> function getBinaryFile(fileSpec) 
 >   Dim adTypeBinary
 >   adTypeBinary = 1 
 >   Dim oStream 
 >   set oStream = server.createobject("ADODB.Stream") 
 >   oStream.Open 
 >   oStream.Type = adTypeBinary 
 >   oStream.LoadFromFile fileSpec 
 >   getBinaryFile= oStream.read 
 >   set oStream=nothing 
e> nd function 

> 

Message #6 by "Ken Schaefer" <ken@a...> on Thu, 12 Sep 2002 17:04:46 +1000
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: <jeff.montgomery@m...>
Subject: [asp_web_howto] Re: File Download Dialog Box


: I have not used the methods you are using, but I had a problem that sounds
: similar, and maybe it's what's happening you your file. I found that the
: FileSystemObject.ReadAll function does not interpret certain characters
: correctly such as nulls, and was ruining my files (they were also Excel
: files).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is probably because the FSO is designed for use with Text files *not*
Binary files... :-)
Check the docs.

Cheers
Ken


  Return to Index