ADODB.stream hangs with some cases of downloading zip files

A

Avi

hello to all the experts,

The following is a code taken from and ASP file, called
downloadgivenfile.asp, that uses the adodb.stream class in order to
download a file from a server. If one wants to download a file, then
typing http://mywebsite/downloadgivenfile.asp?FileName=myfile.exe
would prompt the user with a save open message and followed by a
'save' common dialoog box. Everything works fine with exe files and
cab files, but when I try to download a zip file, something weird is
happens. From all the zip files that I tried to download (i.e., .zip
extension) there very few successes. In those failing cases, I was
prompted with 'save or open' dialog box, and when I press save it
hangs forever without any progress in terms of downloading or
reporting of downloading. If one waits long enough, the an error
message will appear, saying that the server had to disconnect the
connection -- i guess the server noticed thah nothing happens so it
disconnects the connection. In one case where the downmload was
successful with zip file, I renamed the file adding it another
character (e.g., changed the file name from myfile.zip to myfile.zip1)
and the success turned into failure. I did some research on the
internet for quite some time bu I have not founf any answer to that,
maybe because I'm not so familiar with the adodb.stream. Actually the
code you are about to see now is an improvement of some code that
another user on the internet published to the extent of claiming that
it can be used to download any file. Here Any assitance in figuring
out what is going on here an dhow to tackle the problem will be
greatly appreciated. is the code the populates the ENTIRE asp file:

Thank you in advance, Avi


<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>

<body bgcolor="#33ccff">

<%
call DownLoadTheFileInTheQuesryString
function DownLoadTheFileInTheQuesryString()
Dim objStream
RelativeFileNmaePath=Request("FileName")
ThePath="D:\my new web site\"
PathPlusFileName=ThePath & RelativeFileNmaePath
FileName=ReturnFileNameOnlyGivenFilePlusPath(PathPlusFileName)
IsThereSuchFile=DoesFileExist("D:\my new web site\Company_Packages\"
& FileName,objFile)
if IsThereSuchFile=false then
response.Write "<p>File not found Error</p>"
else
Response.Expires = 0
Response.Buffer = true
response.clear
Response.AddHeader "Content-Disposition", "attachment;
filename=" & FileName
lSize =objFile.Size
Response.AddHeader "Content-Length", lSize
Response.Charset = "UTF-8"
ThecontentType=ReturnFilterPropertyForCommonDialogControl(FileName)
Response.ContentType =ThecontentType' "application/zip" '=
ThecontentType'"application/octet-stream"
Response.CacheControl = "public"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromFile PathPlusFileName
CHUNK=2048
NumberofBlocks=(lSize -(lsize mod chunk))/chunk
For lBlocks = 1 To NumberofBlocks
If Response.IsClientConnected = False Then Exit For
Response.BinaryWrite objStream.Read(CHUNK)
Response.Flush
Next
lSize = lSize Mod CHUNK
If lSize = 0 And Response.IsClientConnected = True Then
Response.BinaryWrite objStream.Read(lSize)
Response.Flush

end if

objStream.Close
set objStream = Nothing
Set objFile = Nothing

'response.end
end if
end function
function ReturnFilterPropertyForCommonDialogControl(FileExtension)
select case ucase(FileExtension)
case "EXE"
ReturnedValue="Application/exe"
case "ZIP"
ReturnedValue="Application/zip"
end select
ReturnFilterPropertyForCommonDialogControl=ReturnedValue
'response.write "<p>" & ReturnedValue & "</p>"
end function
function ReturnFileNameOnlyGivenFilePlusPath(PathPlusFileName)
ISItFirstLoop=true
PreviosPosition=0
do while PositionOfForwardSlash<>0 or ISItFirstLoop=true
ISItFirstLoop=false
PreviosPosition=PositionOfForwardSlash
PositionOfForwardSlash= InStr(PositionOfForwardSlash+1,
PathPlusFileName, "\")

loop
ReturnFileNameOnlyGivenFilePlusPath=mid(PathPlusFileName,PreviosPosition+1)
end function
Function DoesFileExist(TheFilePlusPath,FileObject)
Set fso = CreateObject("Scripting.FileSystemObject")
'msgbox fso.getfile(TheFilePlusPath).size

DoesFileExist=fso.FileExists(TheFilePlusPath)
if DoesFileExist=true then set
FileObject=fso.GetFile(TheFilePlusPath)
end function
%>


</body>

</html>
 
E

Egbert Nierop \(MVP for IIS\)

Hi,

You should not set this charset and not write ANY HTML content to the
client. That content, will cause the Content-Length to be incorrect and the
download will corrupt.


Response.CharSEt= "utf-8"
it will cause problems.
Response.AddHeader "Content-Disposition", "attachment;
filename=" & FileName
lSize =objFile.Size
Response.AddHeader "Content-Length", lSize
Response.Charset = "UTF-8"
ThecontentType=ReturnFilterPropertyForCommonDialogControl(FileName)
Response.ContentType =ThecontentType' "application/zip" '=
ThecontentType'"application/octet-stream"
Response.CacheControl = "public"
Set objStream = Server.CreateObject("ADODB.Stream")

Make it CreateObject as well :)
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top