Solved

MIME format and file save dialog question ... again

Posted on 2002-06-27
24
1,378 Views
Last Modified: 2007-11-27
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
0
Comment
Question by:dovholuk
  • 9
  • 8
  • 2
  • +4
24 Comments
 
LVL 2

Expert Comment

by:ManuelMSP
ID: 7113846
Add this code:

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

This should solve the problem. Let me know if not.
0
 
LVL 2

Expert Comment

by:ManuelMSP
ID: 7113867
Add this code:

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

This should solve the problem. Let me know if not.
0
 
LVL 8

Author Comment

by:dovholuk
ID: 7113966
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
0
 
LVL 19

Expert Comment

by:webwoman
ID: 7114007
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. ;-)
0
 
LVL 8

Author Comment

by:dovholuk
ID: 7114040
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
0
 
LVL 2

Accepted Solution

by:
prokni earned 200 total points
ID: 7114136
You can get around it with reading test/a.doc and sending it to browser through your code.
You can use objstream or filesystem object to read your file
somethign like this as your test.asp

'Create a Stream instance
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")

'Open the stream
objStream.Type = adTypeBinary
objStream.Open
objStream.LoadFromFile "path to your doc file"
body = objStream.Read

'Clean up....
objStream.Close
set objStream = Nothing

Response.AddHeader "content-disposition","attachment; filename=" & filename    
Response.ContentType = "application/MS-word"
Response.binarywrite  body
response.end    
0
 
LVL 8

Author Comment

by:dovholuk
ID: 7114430
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
0
 
LVL 2

Expert Comment

by:prokni
ID: 7114574
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
0
 
LVL 8

Author Comment

by:dovholuk
ID: 7114661
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
0
 
LVL 2

Expert Comment

by:prokni
ID: 7114665
pu the full path to your file.
c:\...\test.doc
Don't use the relative path.
0
 
LVL 2

Expert Comment

by:prokni
ID: 7114672
:-)
I didn't read your time frame. that was a cool idea.
0
 
LVL 2

Expert Comment

by:prokni
ID: 7114693
Or
objStream.LoadFromFile Server.MapPath("\test") & "\a.doc"
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 8

Author Comment

by:dovholuk
ID: 7114746
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
0
 
LVL 8

Author Comment

by:dovholuk
ID: 7114753
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
0
 
LVL 2

Expert Comment

by:prokni
ID: 7114836
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.
0
 
LVL 2

Expert Comment

by:prokni
ID: 7115140
Any success? It should work.
lso you can try it  with just putting a text file as sample and see if that works.
0
 
LVL 8

Author Comment

by:dovholuk
ID: 7115498
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
0
 
LVL 7

Expert Comment

by:weesiong
ID: 7115695
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
0
 
LVL 7

Expert Comment

by:weesiong
ID: 7115712
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
%>
0
 
LVL 8

Author Comment

by:dovholuk
ID: 7116299
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
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7116671
hearing...
0
 
LVL 8

Author Comment

by:dovholuk
ID: 7116724
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 : http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=asp&qid=20317374

enjoy!

dovholuk
0
 
LVL 2

Expert Comment

by:prokni
ID: 7116911
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!! :-)
0
 

Expert Comment

by:Denstone
ID: 7366933
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
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now