Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file open/save dialog appearing twice

Status
Not open for further replies.

lonewolf32

Programmer
May 15, 2002
4
US
I am trying to do a file download (zip, pdf, any type really). When I click the link, I get a Open/Save/Cancel dialog as expected. If I click Save, it works OK, opening the Save dialog. But if I click Open, I get another identical Open/Save/Cancel dialog! At this point if I click Open again, it works fine! Here is the code, can anybody help?

File 1 (test.asp):
<HTML>
<HEAD>
</HEAD>
<BODY>
<%session(&quot;axs4mms&quot;) = 1%>
<A HREF=&quot;/scripts/dtest.asp?file=file1.zip&quot;>File 1</A>
</BODY>
</HTML>

File 2 (dtest.asp):
<%
strFile = replace(replace(Request(&quot;file&quot;),&quot;\&quot;,&quot;&quot;),&quot;/&quot;,&quot;&quot;)

' make sure you are on the latest MDAC version for this to work
' -------------------------------------------------------------
' get full path of specified file
strPath = &quot;c:\downloads\&quot;
strFilename = strPath & strFile

' clear the buffer
Response.Buffer = True
Response.Clear

' create stream
Set s = Server.CreateObject(&quot;ADODB.Stream&quot;)
s.Open

' Set as binary
s.Type = 1

' load in the file
on error resume next

' check the file exists
Set fso = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
if not fso.FileExists(strFilename) then
Response.Write(&quot;<h1>Error:</h1>&quot; & strFilename & &quot; does not exist<p>&quot;)
Response.End
end if


' get length of file
Set f = fso.GetFile(strFilename)

s.LoadFromFile(f.name)
if err then
Response.Write(&quot;<h1>Error: </h1>&quot; & err.Description & &quot;<p>&quot;)
Response.End
end if

' send the headers to the users browser
Response.AddHeader &quot;Content-Disposition&quot;, &quot;attachment; filename=&quot; & f.name
Response.AddHeader &quot;Content-Length&quot;, f.size
Response.CharSet = &quot;UTF-8&quot;
Response.ContentType = &quot;application/octet-stream&quot;

' output the file to the browser
Response.BinaryWrite s.Read
Response.Flush

' tidy up
s.Close
Set s = Nothing

%>
 
If I change &quot;attachment&quot; to &quot;inline&quot; the download doesn't allow the user to click Open only Save, so the problem doesn't happen. But I really don't like this solution either.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top