asp.net download File program code
System.IO.FileInfo file = new System.IO.FileInfo (Pstrfilepath);
if (file. Exists)
{
Response.Clear ();
Response.Charset = "GB2312";
response.contentencoding = System.Text.Encoding.UTF8;
Response.AddHeader ("Content-disposition", "attachment;filename=" + server.urlencode (file). Name));
Response.AddHeader ("Conten-length", file. Length.tostring ());
Response.ContentType = "Application/ms-excel";
Response.WriteFile (file. FullName);
Response.End ();
}
The following is a more detailed contenttype
' EZ ' => ' Application/andrew-inset ',
' hqx ' => ' application/mac-binhex40 ',
' CPT ' => ' Application/mac-compactpro ',
' Doc ' => ' Application/msword ',
' Bin ' => ' Application/octet-stream ',
' DMS ' => ' Application/octet-stream ',
' Lha ' => ' Application/octet-stream ',
' Lzh ' => ' Application/octet-stream ',
' exe ' => ' Application/octet-stream ',
' Class ' => ' Application/octet-stream ',
' So ' => ' Application/octet-stream ',
' dll ' => ' Application/octet-stream ',
' Oda ' => ' Application/oda ',
' PDF ' => ' application/pdf ',
' AI ' => ' application/postscript ',
' EPS ' => ' Application/postscript ',
' ps ' => ' application/postscript ',
' SMI ' => ' application/smil ',
' Smil ' => ' application/smil ',
' MIF ' => ' application/vnd.mif ',
' xls ' => ' application/vnd.ms-excel ',
' ppt ' => ' application/vnd.ms-powerpoint ',
' Wbxml ' => ' application/vnd.wap.wbxml ',
' WMLC ' => ' APPLICATION/VND.WAP.WMLC ',
' WMLSC ' => ' APPLICATION/VND.WAP.WMLSCRIPTC ',
' Bcpio ' => ' Application/x-bcpio ',
' VCD ' => ' Application/x-cdlink ',
' PGN ' => ' application/x-chess-pgn ',
' Cpio ' => ' Application/x-cpio ',
' csh ' => ' application/x-csh ',
' DCR ' => ' Application/x-director ',
' dir ' => ' Application/x-director ',
' DXR ' => ' application/x-director ',
' DVI ' => ' Application/x-dvi ',
' SPL ' => ' Application/x-futuresplash ',
' Gtar ' => ' Application/x-gtar ',
' HDF ' => ' APPLICATION/X-HDF ',
' JS ' => ' Application/x-javascript ',
' SKP ' => ' Application/x-koan ',
' SKD ' => ' Application/x-koan ',
' Skt ' => ' Application/x-koan ',
' SKM ' => ' Application/x-koan ',
' Latex ' => ' Application/x-latex ',
' NC ' => ' application/x-netcdf ',
' CDF ' => ' APPLICATION/X-NETCDF ',
' sh ' => ' application/x-sh ',
' Shar ' => ' Application/x-shar ',
' swf ' => ' Application/x-shockwave-flash ',
' Sit ' => ' application/x-stuffit ',
' Sv4cpio ' => ' Application/x-sv4cpio ',
' SV4CRC ' => ' APPLICATION/X-SV4CRC ',
' Tar ' => ' Application/x-tar ',
' Tcl ' => ' application/x-tcl ',
' Tex ' => ' Application/x-tex ',
' Texinfo ' => ' application/x-texinfo ',
' Texi ' => ' application/x-texinfo ',
' t ' => ' Application/x-troff ',
' tr ' => ' Application/x-troff ',
' Roff ' => ' Application/x-troff ',
' Man ' => ' Application/x-troff-man ',
' Me ' => ' application/x-troff-me ',
' Ms ' => ' Application/x-troff-ms ',
' Ustar ' => ' Application/x-ustar ',
' src ' => ' application/x-wais-source ',
' XHTML ' => ' Application/xhtml+xml ',
' Xht ' => ' application/xhtml+xml ',
' Zip ' => ' application/zip ',
' Au ' => ' audio/basic ',
' snd ' => ' audio/basic ',
' Mid ' => ' Audio/midi ',
' Midi ' => ' Audio/midi ',
' Kar ' => ' Audio/midi ',
' MPGA ' => ' audio/mpeg ',
' MP2 ' => ' audio/mpeg ',
' mp3 ' => ' audio/mpeg ',
' AIF ' => ' Audio/x-aiff ',
' Aiff ' => ' Audio/x-aiff ',
' aifc ' => ' Audio/x-aiff ',
' m3u ' => ' Audio/x-mpegurl ',
' Ram ' => ' Audio/x-pn-realaudio ',
' rm ' => ' Audio/x-pn-realaudio ',
' rpm ' => ' audio/x-pn-realaudio-plugin ',
' Ra ' => ' Audio/x-realaudio ',
' WAV ' => ' audio/x-wav ',
"wmv" => ' video/x-ms-wmv ',
"WMA" => ' audio/x-ms-wma ',
' pdb ' => ' chemical/x-pdb ',
' xyz ' => ' chemical/x-xyz ',
' BMP ' => ' image/bmp ',
' gif ' => ' image/gif ',
' Ief ' => ' image/ief ',
' JPEG ' => ' image/jpeg ',
' jpg ' => ' image/jpeg ',
' Jpe ' => ' image/jpeg ',
' PNG ' => ' image/png ',
' TIFF ' => ' Image/tiff ',
' tif ' => ' Image/tiff ',
' DjVu ' => ' Image/vnd.djvu ',
' DJV ' => ' Image/vnd.djvu ',
' Wbmp ' => ' image/vnd.wap.wbmp ',
' ras ' => ' Image/x-cmu-raster ',
' PNM ' => ' Image/x-portable-anymap ',
' PBM ' => ' Image/x-portable-bitmap ',
' PGM ' => ' Image/x-portable-graymap ',
' ppm ' => ' image/x-portable-pixmap ',
' RGB ' => ' Image/x-rgb ',
' XBM ' => ' Image/x-xbitmap ',
' xpm ' => ' Image/x-xpixmap ',
' Xwd ' => ' image/x-xwindowdump ',
' IGs ' => ' model/iges ',
' IGEs ' => ' model/iges ',
' Msh ' => ' Model/mesh ',
' Mesh ' => ' Model/mesh ',
' Silo ' => ' Model/mesh ',
' WRL ' => ' MODEL/VRML ',
' VRML ' => ' MODEL/VRML ',
' CSS ' => ' text/css ',
' HTML ' => ' text/html ',
' htm ' => ' text/html ',
' ASC ' => ' Text/plain ',
' txt ' => ' text/plain ',
' Rtx ' => ' Text/richtext ',
' RTF ' => ' text/rtf ',
' SGML ' => ' TEXT/SGML ',
' SGM ' => ' TEXT/SGML ',
' TSV ' => ' text/tab-separated-values ',
' WML ' => ' text/vnd.wap.wml ',
' wmls ' => ' text/vnd.wap.wmlscript ',
' Etx ' => ' Text/x-setext ',
' xsl ' => ' text/xml ',
' xml ' => ' Text/xml ',
' MPEG ' => ' video/mpeg ',
' mpg ' => ' video/mpeg ',
' Mpe ' => ' video/mpeg ',
' Qt ' => ' video/quicktime ',
' mov ' => ' video/quicktime ',
' Mxu ' => ' Video/vnd.mpegurl ',
' avi ' => ' Video/x-msvideo ',
' Movie ' => ' Video/x-sgi-movie ',
' Ice ' => ' X-conference/x-cooltalk '