Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to force "Save As" dialog

Posted on 2003-03-24
11
Medium Priority
?
410 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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

581 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