Friday, April 9, 2010

Force the users to download rather than opening

For known content types like PDF, doc, mp3 etc..... when you have a download link it just opens it in the browser if the browser knows how to open..

If you want to force the user to download rather than being opened / played in web browser do the following with asp.net

Create a link using a link button and on button click do the following

string myFilename="../docs/abc.doc";

Response.AppendHeader( "content-disposition", "attachment; filename=" + myFilename );

The 2 lines above would force the browser to show the download box .

Hope this Helps.

Bobby