Forum Moderators: phranque

Message Too Old, No Replies

Excel content type-file download bombs

application/msexcel

         

jenwen

6:01 am on Aug 21, 2007 (gmt 0)

10+ Year Member


I have a report which is intended to open in excel format in the browser and also download the file so the client can manipulate the data offline and print it. The page won't open. (I'm using cold fusion, but the functionality I'm using is not cold fusion specific code.)

I made a very basic file to do essentially the same thing for debugging purposes. See code below:

<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<cfcontent type="application/msexcel">
<cfheader name="Content-Disposition"
value="filename=iCal_InternCal.xls">
</head>
<body>
<cfoutput>

<table><tr><td>test</td><td>test1</td><td>test2</td></tr>
<tr><td>testA</td><td>testB</td><td>testC</td></tr></table>

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

That was done to rule out a server call error or other programming
error. The file loads fine on my server. On the client server, it
bombs when it opens the file download dialog box and returns this
error: "Internet Explorer cannot download [filename] from [your
server]. Internet Explorer was not able to open the internet site.
The requested site is either unavailable or cannot be found. Please
try again later."

The client is using Cold Fusion 6.0 on IIS 5 on Windows 2000. I've tested in CF 5.0 on NT and CFMX7 on XP Pro on IE 7 and Firefox. Worked fine for me.

An initial basic test of the file on the client's test CFMX7 server
failed (same error), but they are going to do another test.

Someone pointed me to this blog entry, which seems similar. But the fixes don't work for my problem. (http://www.doughughes.net/index.cfm?event=ViewEntry&entryId=56&showLastComment=true)

Also, I tried changing msexcel to vnd.ms-excel. That gave me a new error:

"Microsoft Office Excel cannot access the file. here are several possible reasons: The file name or path does not exist, the file is being used by another program, the workbook you are trying to save has the same name as a currently open workbook." None of those are actually the case.

Any idea what might be going on? I have no idea where to go from
here. Server config is really not my forte.

Thanks in advance for any suggestions.

Jen

vincevincevince

8:10 am on Aug 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd want to try right-clicking and saving the file instead of opening it with Excel. Having saved it to disk, open the file using notepad and compare it to that which you obtain on the working server.

jenwen

3:16 pm on Aug 21, 2007 (gmt 0)

10+ Year Member



The problem is, the file is created on the fly and downloaded right after. So, there is no filename to click on.

rocknbil

8:01 pm on Aug 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



jenwen, are you trying to force a download of this file or open it?

is intended to open in excel format in the browser

What you need to do to force a download is "munge" the content-type header. By default, browsers will attempt to use helper applications and even "sniff out" the file type if you don't provide a content-type. So before printing the file to the browser, do something like

print "content-type:bad/type\n";

anything will do:

print content-type:sdfsdfasdf\n";

The browser will honor the bad type (even IE!) and force the download.

There are more complications to this, like populating the download box with a file name, and specifying content length, but to cross problems with browser plugins and whatnot I would just force the download and skip the in-browser display. A perl example, which can be duplicated in any language:

# SPECIFY LENGTH: if the file is dynamic, get it from length,
# if it's a temporary file, get it from -s [file]
# length should always be length +1:

$size = length($download_file)+1;

# POPULATE FILENAME IN DOWNLOAD BOX: this should really
# be a dynamic name like "my_results[date].xls"

$filename = 'yourfile.xls';

# print it to the browser with an unrecognizable
# content-type header:

print "content-type: bad/type\n";
print "Content-Length: $size\n";
print "Content-Disposition: attachment; filename=$filename\n\n";
print "$download_file";

vincevincevince

2:30 am on Aug 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is, the file is created on the fly and downloaded right after. So, there is no filename to click on.

Make a new page (straight HTML) containing one link to the page which gives the XLS... then right click that link and 'save link as'

jenwen

9:14 am on Aug 22, 2007 (gmt 0)

10+ Year Member



That is a very, very interesting idea. I already have a hyperlink to the report on a preceding page and your idea works great on my system. I'm going to get them to test it at the client site and see if it works. If so, that could be a work around that the client could live with (and wouldn't have me tearing my hair out doing a complete rewrite). Thanks for the suggestion!

Jen

jenwen

1:32 pm on Aug 22, 2007 (gmt 0)

10+ Year Member


Unfortunately, when I tested your idea out, vincevincevince, a similar error occurred... the file download box started to open, then an error box came up over it saying that internet explorer could not download [Filename] from [Server]. The file could not be written to the cache. :-(

Any other ideas?

Jen

vincevincevince

2:24 pm on Aug 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My first and foremost suspicion in that case is that the problem lies in the cache. Clear the cache from that browser and retry. If possible, establish access from your own PC to the target server and test it there.

If all else fails, use the Server Header Checker [webmasterworld.com] here at WebmasterWorld and post back your results.

jenwen

11:14 pm on Aug 22, 2007 (gmt 0)

10+ Year Member


The cache clear didnt resolve the error. The error she got this time is "Internet Explorer cannot download [filename] from [server]. Internet explorer was not able to open the internet site. The requested site is either unavailable or cannot be found. Plese try again later." That occurred right after the File Download dialog box populated. Same as before.

I can't directly access the site. It is a government site and requires PKI, which I don't have. The server header checker can't find it for the same reason.

vincevincevince

12:33 am on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Manual checking of server headers:

First, launch command prompt ( Run > cmd )

Type:

telnet www.example.com 80
<press Ctrl+]>
set localecho
<press enter twice>
HEAD /file/path.html HTTP/1.1
Host: www.example.com

<press enter twice>

In the above, < > denotes an instruction rather than something you type

This is optional, it just lets you see what you are typing (which is nice):

<press Ctrl+]>
set localecho
<press enter twice>

If you use IP based hosting then it is even shorter:

telnet www.example.com 80
HEAD /file/path.html
<press enter twice>

To see the entire produced file, then change 'HEAD' to 'GET' in the above code. It is probably instructive to compare what is produced there with what is produced by your own server.

Something else which occurs to me is that there may be something in the server error log - go and have a look.

jenwen

3:52 pm on Aug 30, 2007 (gmt 0)

10+ Year Member


I was unable to complete the server header check.

When tried the head command "HEAD /iCal/calendar_pe_test3.cfm HTTP/1.1 it said "HEAD is not recognized as an internal or external command."

I also tried it with the Host: [web address] immediately following. Same error.

jtara

4:08 pm on Aug 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you try this?

To see the entire produced file, then change 'HEAD' to 'GET' in the above code.

Sounds like for some reason your web server doesn't support the HEAD HTTP request. Seems very odd. Are you sure you followed the instructions and telnetted into your web server? Make sure to include the port number - 80 - otherwise you will telnet into your telnet server - NOT what you are trying to do!

From the output you got, that's what it sounds like happened - that sounds like an error message from a Linux command-line interpreter - not from a web server!

jenwen

4:12 pm on Aug 30, 2007 (gmt 0)

10+ Year Member



I got the same error.

Thx.

Jen

jenwen

8:33 pm on Aug 30, 2007 (gmt 0)

10+ Year Member


I did telnet in. Did use the port number. Got no satisfaction.
:-( They specifically said they were using port 80 too. I had no problem until I got to the HEAD line.

Jen

jtara

4:54 pm on Aug 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I did telnet in. Did use the port number. Got no satisfaction.

Somehow, you didn't though.

The error message you got is the error message that a Windows command prompt gives for an unrecognized command.

I'm guessing that you either telnetted into the standard telnet port of 25 on a Windows machine, or else telnet never connected and exited, leaving you at a Windows command prompt.

In any case, you seem to have connected to a Windows command prompt, not a web server.

Experiment with this first using known-good websites - e.g. yahoo.com.

jenwen

6:49 pm on Aug 31, 2007 (gmt 0)

10+ Year Member



I tried telnetting another way (the way I know). (apostrophes just indicate what I typed. I didn't type the apostrophes.)

I opened a command prompt, typed 'telnet' and hit return. Then I tried 'open www.yahoo.com 80' and hit return. It tried to connect.. there was a long pause, then it said press any key to continue. I pressed a key and it said connection to host lost and put me back at the prompt..

Am I doing something wrong? That should work, right? I also tried it with my personal website. Same thing.

Jen

jtara

5:06 pm on Sep 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Then I tried 'open www.yahoo.com 80' and hit return...

...Am I doing something wrong?

Yup.

Just type "telnet yahoo.com 80" at the Windows command prompt. Windows telnet doesn't accept a port number on the "open" line once you are running telnet interactively. You have to specify it on the command line.

jenwen

7:10 am on Sep 4, 2007 (gmt 0)

10+ Year Member



I do that and get a black screen with a blinking white cursor at the top.

jenwen

7:17 am on Sep 4, 2007 (gmt 0)

10+ Year Member



eventually it puts me back at the command prompt.. c:/... yadda yadda

Jen

jtara

5:34 pm on Sep 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I do that and get a black screen with a blinking white cursor at the top.

That's what you should get. Just type commands at it, and you will get the response. You will not get an echo of your commands. (You can follow the instructions above to turn on echo, but there's really no need.)

Remember to hit "return" twice.

Alternately, there are Firefox plugins that will make it easier for you to analyze your site's HTTP responses.

jenwen

9:27 am on Sep 5, 2007 (gmt 0)

10+ Year Member



So, I tried this with yahoo first. I did get data back once I set the localecho. But then my connection would drop before I could do anything else. I tried several times.

I tried the client site then. I did the same thing.. it said it connected.. I got the black screen with the blinking cursor. When I tried to set the local echo.. nothing. I tried the other commands.. nothing. Couldn't find a command to exit.. tried exit bye close quit Ctrl+K and Ctrl+C

Finally just closed the window.

Argh.

jtara

6:58 pm on Sep 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I did get data back once I set the localecho. But then my connection would drop before I could do anything else.

That is correct. HTTP is a "connectionless" protocol. You make one request, the server sends you one response, and then disconnects. That's the way all web servers work.

It's really useful for a webmaster to learn the basics of the HTTP protocol. You can diagnose a lot of problems with a basic knowledge of what is happening when a user connects to your server.

This is why it isn't worth the bother setting local echo. You will see your one short command typed, see the response, and then have to run telnet again if you want to test something else.

As I mentioned before, there are other tools that are much easier to use than "telnet" for this ("live HTTP headers" extension for Firefox, for example), but telnet is the most basic, and it's worthwhile to learn how to use telnet to diagnose server problems. You can use it to test MOST Internet protocols - HTTP, SMTP, POP, etc. etc.

jenwen

9:06 pm on Sep 5, 2007 (gmt 0)

10+ Year Member



But, I never got to type the HEAD command. The connection dropped before I could. So, I never got the data. ? And I couldn't get any information back when I contacted the web site I needed to see. Just the black screen n cursor. I feel a little lost here.

Jen

jdMorgan

9:26 pm on Sep 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Jen,

Rather than going through the pain of learning and using telnet when your problem has been outstanding for two weeks, let me echo the advice --posted several times now-- that you install the Live HTTP Headers [livehttpheaders.mozdev.org] extension for Firefox [mozilla.com] and all other modern Mozilla-based browsers.

By selecting "Live HTTP Headers" from the "Tools" menu in Firefox/Mozilla, you can turn on a live display of the full browser and server headers which will most likely clarify your problem in one step.

All you need to do is to check that the Content-type header returned by the server is "application/vnd.ms-excel" when the Excel spreadsheet is requested by the client.

Jim

jenwen

12:31 am on Sep 6, 2007 (gmt 0)

10+ Year Member



I can test this at home, but not at the client site. They do not permit Firefox. That is why I haven't followed that chain yet.. But I'll try it here. Thanks Jim.

Jen

jenwen

1:03 am on Sep 6, 2007 (gmt 0)

10+ Year Member



Ok.. I tried.. didn't work.. talked to another techie I know and he seems to think that a secure military server probably wouldn't allow me to telnet in. The live headers also did not return anything. Just kept working and working and working. So, I'm going to see if someone at the client site in their IS dept would be willing to do it. Its a long shot.. but doesn't hurt to ask.

jenwen

1:06 am on Sep 6, 2007 (gmt 0)

10+ Year Member



Oh, and server log was completely unhelpful. Had another techie look at it too. Nothing exciting.

jtara

3:59 am on Sep 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



talked to another techie I know and he seems to think that a secure military server probably wouldn't allow me to telnet in.

If the website is accessible, you can use a telnet program to test it.

It's important to distinguish between telnet "the program" (more specifically, a telnet client program), and telnet "the protocol".

telnet is a protocol for interactively accessing a command shell over TCP/IP. It normally runs on port 23. The techie is right in that a secure military site is unlikely to be running a telnet server.

It turns out though, that telnet "the protocol" is very simple, as are most Internet protocols. It turns out that it is SO simple, and most Internet protocols are also so simple (text line-oriented) that one can use a telnet client to test and diagnose most Internet protocols if the telnet client can be told to connect on a different port.

When you use telnet to connect to an HTTP server (typically on port 80) you are simply using the telnet client instead of a web browser.

The live headers also did not return anything.

Well, then, your problem is simple - the website is down! ;)

OK, serious answer - once you have installed Live Headers, close and then re-open Firefox. (Make sure to close ALL open Firefox windows.) Click on Tools, Live Headers, and you will get a pop-up Live Headers window. You should see every header sent by every web site you access. Try it here on WebmasterWorld - I'm using it right now, and it works just fine.