TenTonJim
asked on
Force download of text file
I need to know the syntax for...
when the user clicks on a hyperlink it downloads a .txt file instead of the browser rendering the .txt file.
Thank you,
JimS.
when the user clicks on a hyperlink it downloads a .txt file instead of the browser rendering the .txt file.
Thank you,
JimS.
ASKER
Yes. I do not want it to render.
I want the download prompt box asking me where to save it.
Thanks,
JimS.
I want the download prompt box asking me where to save it.
Thanks,
JimS.
ASKER
Yes. I do not want it to render.
I want the download prompt box asking me where to save it.
Thanks,
JimS.
I want the download prompt box asking me where to save it.
Thanks,
JimS.
This is a client-side setting.
A few options:
You could save the file as a different format, archive it in a zip file (silly for one text file), include text on you're webpage that suggest that your users chose the "save as" option.
-corey
A few options:
You could save the file as a different format, archive it in a zip file (silly for one text file), include text on you're webpage that suggest that your users chose the "save as" option.
-corey
I had the same question not to long ago and i found this code that worked for me...check out the link
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2183&lngWId=2
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2183&lngWId=2
then you want to set the content type that would force the browser to prompt the user to save.. such as "application/octet-stream" or something.
menreeq: please do not propose answers unless you are 200% sure it is the absolute only way to accomplish the task. Please look at the bottom of this page for more info.
CJ
menreeq: please do not propose answers unless you are 200% sure it is the absolute only way to accomplish the task. Please look at the bottom of this page for more info.
CJ
Ohh i see, first time answering a question. Thanks for the tip
ASKER
thank you menreeq, and I may use that answer.
cheekycj, could you explain a little further?
Thanks,
JimS.
cheekycj, could you explain a little further?
Thanks,
JimS.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is what I got working...
response.setContentType("A PPLICATION /OCTET-STR EAM");
response.setHeader("Conten t-Disposit ion","atta chment; filename=\""+ filename + "\"");
java.io.FileInputStream fileInputStream =new java.io.FileInputStream(fi lepath+fil ename);
int i;
while ((i=fileInputStream.read() ) != -1) {
out.write(i);
}
fileInputStream.close();
out.close();
Thanks everyone!
JimS.
response.setContentType("A
response.setHeader("Conten
java.io.FileInputStream fileInputStream =new java.io.FileInputStream(fi
int i;
while ((i=fileInputStream.read()
out.write(i);
}
fileInputStream.close();
out.close();
Thanks everyone!
JimS.
Glad I could help, Thanx for the "A"
CJ
CJ
but you can write a JSP that will read the text file.
You can use FileReader to read the file.
and then set the content type of the JSP to
"text/html"
using response.setContentType("t
CJ