How to force "Save As" dialog

Hi, I'm linking to a .txt file on my webpage, and internet explorer displays the contents of the file when a user clicks on the link. I would like to force the user to download the file to his HD instead of viewing it online.

LebThug
LebThugAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nbthanhCommented:
Hi,
I think there's no way to do this if that txt file is not on in your directory.

If, however, that txt file is yours and your web server support .htaccess file, you can put some thing like this into your .htaccess:

<Files yourfile.txt>
    ForceType  application/octet-stream
</Files>

Or you want to apply this to all .txt files:
<Files *.txt>
    ForceType  application/octet-stream
</Files>

Note: this may not work with all server!

Hope this help.
0
LebThugAuthor Commented:
Hi,
thanks for the suggestion, but unfortunately i am using IIS and .htaccess is not supported.
Do you know a way to do it with IIS?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

LebThugAuthor Commented:
Hi,
thanks for the suggestion, but unfortunately i am using IIS and .htaccess is not supported.
Do you know a way to do it with IIS?
0
mattjp88Commented:
<input TYPE="Button" VALUE=download onclick="execCommand('saveas','','test.txt')">

matt:-)
0
nbthanhCommented:
Hi LebThug,
If you are on IIS and you link to a txt file on *another* server that is running Apache *and* you have control of that server, then you can use .htaccess.

Or, if you have control of IIS, you can change the MINE type of .txt file into application/octet-stream (find the File types setting under the HTTP Headers tab of IIS Web site properties dialog).

Otherwise, I can't think of a way to solve your problem :-)

to mattjp88: I think your code will save the 'current page' as test.txt, not save the 'linked' test.txt file. Correct me if I'm wrong :-)

Hope this help.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mattjp88Commented:
well... you are.  i tested it.  it will save the file test.txt.  try it out.  just make a blank file named "test.txt" and then an html file with "<input TYPE="Button" VALUE=download onclick="execCommand('saveas','','test.txt')">"  in it.  then try it out.  it will save the file, not the web page.

matt :-)
0
nbthanhCommented:
Hi mattjp88,

I've tested it and found something :-)

- It saved a blank test.txt file onto the disk
- But it is not the test.txt file on the server!

You can retest by this simple step:
- Put some text into your test.txt -> the saved test.txt will be still blank!
- Put some text in your html page (eg 'blablabla'), the saved test.txt file will contain 'blablabla'
- Or...delete your test.txt file, change execCommand('saveas','','test.txt') into execCommand('saveas','','blablabla.txt')
A blank file named blablabla.txt will be saved :-)

All this is because you save your web page as a txt file, all 'visible' text will be saved. And because your web page just have a button, which is not considerred as a 'visivle' text for txt file, a blank file will be saved.

Correct me if I'm wrong :-)
0
mattjp88Commented:
oh.  i was wrong :-(.  i thought it would work, but i never actually tried it.  sorry :-(
0
LebThugAuthor Commented:
Thanks for your solution! I did the changes in IIS, but it didn't work at first; turned out i had to start the SMTP server too.

thanks a lot
LebThug
0
nbthanhCommented:
Well,

>"I did the changes in IIS, but it didn't work at first; turned out i had to start the SMTP server too."

Thanks LebThug, I will remember this for latter use :-)

Best wishes!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.