Force a link to download instead of open in IE

  • Thread starter Thread starter Mufasa
  • Start date Start date
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.
 
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();
}
 
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.
 
I see, because of the "attachment" in the Content-Deposition

Thanks
George.
 
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 :-))
 
Back
Top