Force a link to download instead of open in IE

M

Mufasa

Is there a way to have a link in IE that will automatically run the saveas
command instead of trying to open the file?

TIA - Jeff.
 
G

Guest

Is there a way to have a link in IE that will automatically run the saveas
command instead of trying to open the file?

TIA - Jeff.

Hi Jeff

you can do it using code. For example, you can have a LinkButton with
the following code in it

protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition",
"attachment;filename=test.doc");
Response.WriteFile(Server.MapPath("~/test.doc"));
Response.Flush();
Response.Close();
}
 
G

George Ter-Saakov

I believe that IE will open up the word document on IE. Depends on the
settings.

But I think that if you pass content type unrecognizable by browser then IE
will open Save As window since it would not know what application to use.

Try to add to the code bellow following line

Response.ContentType="blablba";

Might work or might not

George.
 
G

George Ter-Saakov

I see, because of the "attachment" in the Content-Deposition

Thanks
George.
 
G

Guest

I found where my "believes" came fromhttp://support.microsoft.com/default.aspx/kb/267991

turned out IE 5.5 would open file inside instead of popping dialog. despite
of the attachment word.

George.

That thought about old browsers has crossed my mind. SP1 for 5.5 has
fixed that issue 7 years ago :))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top