mdanny
asked on
Download excel file without opening it in a browser.
Here is the situation:
<A href=file://D:\TestWeb\The ExcelFile. xls>This is the one</A>
How can I let the user click on this link to Excel file and recieve a SaveFile dialog? What happens is that Excel file is opened in the browser.
<A href=file://D:\TestWeb\The
How can I let the user click on this link to Excel file and recieve a SaveFile dialog? What happens is that Excel file is opened in the browser.
Response.ContentType()
Sorry;
content-type header
More details shortly.
content-type header
More details shortly.
I think you will need to create a page. Make the link point to the new page. In the page you will need to set the header and then send the binary contents of the file.
forcing browser to save text file(or other files)
in most cases, you will find that the browser is already configured to open a MIME type text
file, so pushing a .txt file to save will have to be controlled via a header. Try this;
Response.AddHeader "content-disposition","att achment; filename=NewFileName.xls"
More details can be found at http://support.microsoft.com/support/kb/articles/Q260/5/19.ASP
here is some code to give you an idea of how to send the binary info. The example is meant to be used for images... but you can convert it easily.
forcing browser to save text file(or other files)
in most cases, you will find that the browser is already configured to open a MIME type text
file, so pushing a .txt file to save will have to be controlled via a header. Try this;
Response.AddHeader "content-disposition","att
More details can be found at http://support.microsoft.com/support/kb/articles/Q260/5/19.ASP
here is some code to give you an idea of how to send the binary info. The example is meant to be used for images... but you can convert it easily.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
John, that's the same link and code from the link I provided...
just trying to clarify and give examples. you mentioned using content-type header and I was only pointing out that you need to use content-disposition. The link just happened to be in the section of code I usually post in these cases. Not trying anything sneaky here.
John
John
I know... ;-)
just listening- I have a similar issue-
ASKER
This code doesn't work.I get an error :
Response object error 'ASP 0156 : 80004005'
Header Error
/TestWeb/Default.asp, line 4
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.
Response object error 'ASP 0156 : 80004005'
Header Error
/TestWeb/Default.asp, line 4
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.
ASKER
This code doesn't work.I get an error :
Response object error 'ASP 0156 : 80004005'
Header Error
/TestWeb/Default.asp, line 4
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.
Response object error 'ASP 0156 : 80004005'
Header Error
/TestWeb/Default.asp, line 4
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.
ASKER
This code doesn't work.I get an error :
Response object error 'ASP 0156 : 80004005'
Header Error
/TestWeb/Default.asp, line 4
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.
Response object error 'ASP 0156 : 80004005'
Header Error
/TestWeb/Default.asp, line 4
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.
ASKER
Sorry for that...
You're not trying to redirect to another page are you?
Usually the fix to HTTP headers being written is to add Response.Buffer = True at the very top of the page (before any actual page content gets written)
Usually the fix to HTTP headers being written is to add Response.Buffer = True at the very top of the page (before any actual page content gets written)
Something like
<<start page>>
<html>
<% 'Add Header %>
</html>
<<end page>>
Is not going to work, because the headers and html tags are already printed on the page.
<<start page>>
<html>
<% 'Add Header %>
</html>
<<end page>>
Is not going to work, because the headers and html tags are already printed on the page.
you just add the following line at the beginning
response.contentType = "application/vndms-word"
response.contentType = "application/vndms-word"
devenkhatri, welcome to Experts Exchange, we hope you enjoy yourself and active in discussions. However, I must inform you that there are a few basic rules that must be adhered to if you want to make friends with the experts here.
First of all, read this; https://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp
It is full of good innformation. Second of all, never, ever copy another experts comment and propose it as your "answer" as you have done above. If you read the comments and followed the thread you would have read that both myself and John already mentioned ContentType.
But even further, your proposed "answer" will do nothing except what mdanny is trying to avoid, all "response.contentType = "application/vndms-word"" does it tell the browser to open the file as an Excel application, if you read the Q mdanny is trying to open the File Save As dialog box. Which is what the following does;
Response.AddHeader "content-disposition","att achment; filename=NewFileName.xls"
Do us a favor and retract your "answer", then read the question and the comments prior to posting anything, if you have something to add please do.
First of all, read this; https://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp
It is full of good innformation. Second of all, never, ever copy another experts comment and propose it as your "answer" as you have done above. If you read the comments and followed the thread you would have read that both myself and John already mentioned ContentType.
But even further, your proposed "answer" will do nothing except what mdanny is trying to avoid, all "response.contentType = "application/vndms-word"" does it tell the browser to open the file as an Excel application, if you read the Q mdanny is trying to open the File Save As dialog box. Which is what the following does;
Response.AddHeader "content-disposition","att
Do us a favor and retract your "answer", then read the question and the comments prior to posting anything, if you have something to add please do.
Remember, Response.ContentType will tell the browser how to handle the file, content-disposition tells the browser to raise the "File Save As" dialog box. You need to read this; http://support.microsoft.com/support/kb/articles/Q260/5/19.ASP