Try
{
String fullfilename = server. mappath ();
Fileinfo downloadfile = new fileinfo (fullfilename );
If (downloadfile. exists)
{
Response. Clear ();
Response. clearheaders ();
Response. Buffer = false;
Response. contenttype = "application/octet-stream ";
Response. appendheader ("content-disposition", "attachment; filename =" + httputility. urlencode (downloadfile. fullname, system. Text. encoding. ASCII ));
Response. appendheader ("Content-Length", downloadfile. length. tostring ());
Response. writefile (downloadfile. fullname );
Response. Flush ();
Response. End ();
}
Else {
// The file does not exist.
}
}
Catch
{
// The file does not exist.
}
The following are common contenttypes:
'Doc' => 'application/msword ',
'Bin' => 'application/octet-stream ',
'Exe '=> 'application/octet-stream ',
'Class' => 'application/octet-stream ',
'Dll '=> 'application/octet-stream ',
'Xls '=> 'application/vnd. MS-Excel ',
'Ppt '=> 'application/vnd. MS-PowerPoint ',
'Vcd' => 'application/X-cdlink ',
'Dir' => 'application/X-ctor ', 'dxr' => 'application/X-Director ',
'Dvi '=> 'application/X-DVI ',
'Spl' => 'application/X-futuresplash ',
'Js' => 'application/X-JavaScript ',
'Swf '=> 'application/X-Shockwave-flash ',
'Src' => 'application/X-WAIS-source', 'xhtml '=> 'application/XHTML + xml ',
'Mp2' => 'audio/MPEG ',
'Mp3' => 'audio/MPEG ',
'Wav '=> 'audio/X-WAV ',
"WMV" => 'video/X-MS-WMV ',
"WMA" => 'audio/X-MS-WMA ',
'Pdb' => 'chemical/X-pdb ',
'Bmp '=> 'image/BMP ',
'Gif' => 'image/gif ',
'Jpeg '=> 'image/JPEG ',
'Jpg '=> 'image/JPEG ',
'Jpe' => 'image/JPEG ',
'Png '=> 'image/PNG ',
'Css '=> 'text/CSS ',
'Html' => 'text/html ',
'Htm '=> 'text/html ',
'Asc '=> 'text/plain ',
'Txt '=> 'text/plain ',
'Rtx' => 'text/richtext ',
'Rtf '=> 'text/RTF ',
'Xsl '=> 'text/xml ',
'Xml' => 'text/xml ',
'Mpeg '=> 'video/MPEG ',
'Mpg' => 'video/MPEG ',
'Av' => 'video/X-msvideo ',
'Movi' => 'video/X-SGI-movi ',