?
Solved

How to force "Save As" dialog

Posted on 2003-03-24
11
Medium Priority
?
396 Views
Last Modified: 2008-02-26
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
0
Comment
Question by:LebThug
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 1

Expert Comment

by:nbthanh
ID: 8195873
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
 
LVL 17

Expert Comment

by:dorward
ID: 8196105
0
 

Author Comment

by:LebThug
ID: 8197300
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
WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

 

Author Comment

by:LebThug
ID: 8197417
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
 
LVL 6

Expert Comment

by:mattjp88
ID: 8198391
<input TYPE="Button" VALUE=download onclick="execCommand('saveas','','test.txt')">

matt:-)
0
 
LVL 1

Accepted Solution

by:
nbthanh earned 150 total points
ID: 8199502
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
 
LVL 6

Expert Comment

by:mattjp88
ID: 8199638
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
 
LVL 1

Expert Comment

by:nbthanh
ID: 8199676
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
 
LVL 6

Expert Comment

by:mattjp88
ID: 8199711
oh.  i was wrong :-(.  i thought it would work, but i never actually tried it.  sorry :-(
0
 

Author Comment

by:LebThug
ID: 8203488
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
 
LVL 1

Expert Comment

by:nbthanh
ID: 8203521
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

Featured Post

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

765 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