Link to home
Start Free TrialLog in
Avatar of dovholuk
dovholuk

asked on

MIME format and file save dialog question ... again

ok. so i've got to be mentally challenged. could somebody help out a mentally challenged "expert"? for the life of me i can't force a download dialog box to pop up when IE (haven't even bothered with netscape) knows the MIME type and tries to open the file in the internet browser...

here's "all" i want to do. click my link to an .asp page that picks the "right" file (call it a.doc or a.xls), and prompts the user to open it from current location or save to disk.

i KNOW it's doable, i just can't for the life of me make it work.

full credit will only be given if someone provides the code. i won't accept hyperlinks.

this MUST be simple... i've looked all over the net and i've found nothing that "works" for me yet. *sigh*.

hopefully this question is moronically simple and i get an answer speedily as i'm sick of feeling stupid over this!!! lol! ;-)  the server runs IIS 4 with sp6 installed. i've tried all the answers in the EE db (that i could find that pertain to this issue) and still i can't make it happen. i've tried using an ADO recordset, opening the file using the FSO, and even "including" the file. i do NOT have office installed on the server, do i need to? it seems that ADO won't open the file which leads me to believe that the server needs office installed?

anyway... i'll slide the scale too as i want the answer NOW, if i get a response within:
     - 30 minutes from the timestamp = 200 points
     - 1 hr from timestamp = 150 pts
     - 2 hr from timestamp = 100 pts
     - other = 50 pts..

i'll check back every 5-10 minutes and try suggestions pronto.

thanks

dovholuk
Avatar of ManuelMSP
ManuelMSP

Add this code:

<%Response.AddHeader "content-disposition", "attachment; filename=xxx.ext"%>

This should solve the problem. Let me know if not.
Add this code:

<%Response.AddHeader "content-disposition", "attachment; filename=xxx.ext"%>

This should solve the problem. Let me know if not.
Avatar of dovholuk

ASKER

ok. here's what's up:

i have a file located at: http://MyServerIP/test/a.doc
i have this asp file at http://MyServer/test/test.asp :

<%@ LANGUAGE = "VBScript" %>
<%Response.AddHeader "content-disposition", "attachment; filename=http://MyServerIP/test/a.doc"%>
<html>
<body>
</body>
</html>

when i run http://MyServer/test/test.asp , the file dialog tries to download the source of http://MyServer/test/test.asp (after the server produces it of course) which consists entirely of:

<html>
<body>
</body>
</html>


this is exactly what WAS happening... what am i doing wrong?

thanks for any input.

dovholuk
That's exactly what you told it to do -- save THIS document with THIS name.

You can't do what you want that way. You have to tell the server to send the OTHER file. Adding headers adds them to the EXISTING file, which isn't what you need.

I suspect you have to use FSO, but I don't use that enough... somebody will likely come along with the right code. ;-)
i was under the impression that:
<%Response.AddHeader "content-disposition", "attachment; filename=http://MyServerIP/test/a.doc"%>

told the server to send the file specified by the "attachment; filename=" it doesn't? i find that odd...

thanks for the input though...

dovholuk
ASKER CERTIFIED SOLUTION
Avatar of prokni
prokni

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks for the input. 2 problems. when i run the code i get:
<ERROR>
ADODB.Stream error '800a0bb9'

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

/test/test.asp, line 7
</ERROR>

any clue as why?

second, i do NOT have office installed on the server, will it still be able to find a class that corresponds to "application/MsWord"? i don't think it will. that brings up the follow up question, do i need to install office on the server so that IIS can create an instance of word using "application/MsWord" or is "application/MsWord" simply something that is passed BACK to the client?

Thanks.

dovholuk
You need to include adovbs.inc or define the keyword as const
for example
Const adTypeBinary = 1
Actually this is enough for you.
About the second issue, i don't think so. that is just notification to browser about the file format.
Client needs to have a coresponded software in order to deal with that type of fiel format.
Just try it and see how it works
ok i forgot to change the adTypeBinary, no biggie... what does THIS error mean... btw. if you can get this to work, i'll still dish out 200 pts even though it's past the 30 minute deadline...

(points upped to 200)

<ERROR>
    ADODB.Stream error '800a0bba'
   
    File could not be opened.
   
    /test/test.asp, line 10
</ERROR>

dovholuk
pu the full path to your file.
c:\...\test.doc
Don't use the relative path.
:-)
I didn't read your time frame. that was a cool idea.
Or
objStream.LoadFromFile Server.MapPath("\test") & "\a.doc"
ok... here's the exact code i'm using:

<%
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.LoadFromFile "g:\a.doc"
body = objStream.Read
objStream.Close
set objStream = Nothing
Response.AddHeader "content-disposition","attachment; filename=a.doc"
Response.ContentType = "application/MS-word"
Response.binarywrite  body
response.end
%>

still getting:
<ERROR>
ADODB.Stream error '800a0bba'

File could not be opened.

/test/test.asp, line 6
</ERROR>

i'm not far from trying to install office on the server... why the *bleep* doesn't this work for me???? i'm going insane! insane i tell you!!!! :-)

dovholuk
also, i've tried:
<%
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.LoadFromFile "g:\a.doc"
body = objStream.Read
objStream.Close
set objStream = Nothing
Response.AddHeader "content-disposition","attachment; filename=g:\a.doc"
Response.ContentType = "application/MS-word"
Response.binarywrite  body
response.end
%>


and yes, i'm sure g:\a.doc exists! :-)

dovholuk
You don't need to install office, i am service doc file and pdf file off of my apache web server on sun solaris and it wokrs great. i just set the mime format. There is no offic eon Sun:-)
I have a meeting for 2 hours I get back to you after that. Copy your file to c:\ and try to open it from there.
See what happens.
Also we can try it with FSO too to read the file content.
Any success? It should work.
lso you can try it  with just putting a text file as sample and see if that works.
to date no progress...

don't know what the issue is. if you've got no other ideas (and i'm surprised no other person has offered input) i'll delete this question and post a 100 pointer for your "efforts" here.

thanks

dovholuk
dovholuk,

Maybe sure your ADO is 2.5+

and add this line :

<!--METADATA TYPE="typelib"
      UUID="00000205-0000-0010-8000-00AA006D2EA4"
     NAME="ADODB Type Library"
-->
<%
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = adTypeBinary
objStream.Open
objStream.LoadFromFile "g:\a.doc"
objStream.Close
set objStream = Nothing
Response.AddHeader "content-disposition","inline; attachment; filename=a.doc"
Response.ContentType = "application/MS-word"
Response.binarywrite  objStream.Read
response.end
%>

Regards,
Wee Siong
change my code to :

<!--METADATA TYPE="typelib"
     UUID="00000205-0000-0010-8000-00AA006D2EA4"
    NAME="ADODB Type Library"
-->
<%
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = adTypeBinary
objStream.Open
objStream.LoadFromFile "g:\a.doc"
Response.AddHeader "content-disposition","inline; attachment; filename=a.doc"
Response.ContentType = "application/MS-word"
Response.binarywrite  objStream.Read
objStream.Close
set objStream = Nothing

response.end
%>
sorry. no luck... same can't open file error... also i didn't get 2 notif's for your posts... darn notifs must be slow or down again... thanks anyway.

i am positive i have MDAC 2.5 installed which i believe is also ADO 2.5... i'm looking into installing mdac 2.7 now. i doubt it'll fix anything, but if it does i'll grant the 200 pts to you weesiong.

prokni, i'll post a 100 point question for your input as promised.

i'll leave this question open for 4 more hours (maybe more, maybe less) hoping for more responses...

dovholuk
Avatar of Richie_Simonetti
hearing...
maybe you mean listening richie??? :-)

anyway. found out the issue with can't open the file... permissions were set for admin only, needed to grant permissions to IIS for it to serve "properly"...

so after trying to figure this out for 1.2 billion hours, it turns out that my only problem was that i didn't grant priv's to READ the damned file...

oi.

on trying the old code the code i had originally (sickening almost identical to what prokni posted at Date: 06/27/2002 08:43AM PST ) turned out to work just fine.

as a side note, "application/MS-WORD" needed to be changed to "application/msword" other than that, the above code WILL work if permissions are set properly...

*sigh* all this effort and i just didn't have permissions on the file set right...

anyway, this is a REALLY good discussion which includes permission issues that i didn't find elsewhere in ee, so i'm going to award prokni the pts.

weesiong, for your input as well, jump to the question i posted for prokni (100 pointer) at : https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=asp&qid=20317374

enjoy!

dovholuk
Most of the time, problem is so simple that we can not see it. I was wrestling with my perl code on one of our web server and I could not get it run. After couple hours my frinds just walked in and asked me if I have Perl installed on my server!! :-)
The IUSR_<machinename> account needs NTFS RW (read/write) permissions to the folder in question for the ADO stream object to be able to read the file off the disk.

Cheers
Denstone