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 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>
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 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>