[导入]关于返回文件的补充说明
在返回文件的load文件中,应该给返回的文件加上文件头,比如应该用
Response.AddHeader("Content-Length",iStream.Length.ToString());
语句来给出文件大小,要不客户端下载就没有进度条,这样对用户是很不方便的
本来我希望通过Response.AddHeader("Content-Length",iStream.Length.ToString());
还有就是最重要的文件的MIME编码,如果这个设置不正确,会有很多问题,我在网上找了很久都没有一个好的解决方法,只好这样:
Response.ContentType = GetContentType(fileSpec);
private string GetContentType(string fileSpec)
{
string contentType;
switch (Path.GetExtension(fileSpec))
{
case ".3gp": contentType="audio/AMR-WB-encrypted"; break;
case ".m4a": contentType="audio/m4a"; break;
case ".mid": contentType="audio/midi"; break;
case ".mp1": contentType="audio/mp1"; break;
case ".mp2": contentType="audio/mp2"; break;
case ".mp3": contentType="audio/mpeg"; break;
case ".m3u": contentType="audio/mpegurl"; break;
case ".mpga": contentType="audio/rn-mpeg"; break;
case ".pls": contentType="audio/scpls"; break;
case ".ra": contentType="audio/vnd.rn-realaudio"; break;
case ".wav": contentType="audio/wav"; break;
case ".aiff": contentType="audio/x-aiff"; break;
case ".wax": contentType="audio/x-ms-wax"; break;
case ".wma": contentType="audio/x-ms-wma"; break;
case ".aif": contentType="audio/x-pn-aiff"; break;
case ".au": contentType="audio/x-pn-au"; break;
case ".ram": contentType="audio/x-pn-realaudio"; break;
case ".rms": contentType="audio/x-realaudio-secure"; break;
case ".bmp": contentType="image/bmp"; break;
case ".gif": contentType="image/gif"; break;
case ".jpg": contentType="image/jpeg"; break;
case ".png": contentType="image/png"; break;
case ".tif": contentType="image/tiff"; break;
case ".rp": contentType="image/vnd.rn-realpix"; break;
case ".ico": contentType="image/x-icon"; break;
case ".xbm": contentType="image/x-xbitmap"; break;
case ".css": contentType="text/css"; break;
case ".htm": contentType="text/html"; break;
case ".uls": contentType="text/iuls"; break;
case ".txt": contentType="text/plain"; break;
case ".wsc": contentType="text/scriptlet"; break;
case ".rt": contentType="text/vnd.rn-realtext"; break;
case ".htt": contentType="text/webviewhtml"; break;
case ".htc": contentType="text/x-component"; break;
case ".vcf": contentType="text/x-vcard"; break;
case ".xml": contentType="text/xml"; break;
case ".3g2": contentType="video/3gpp2"; break;
case ".mpeg": contentType="video/mpeg"; break;
case ".avi": contentType="video/msvideo"; break;
case ".rv": contentType="video/vnd.rn-realvideo"; break;
case ".mpa": contentType="video/x-mpg"; break;
case ".asx": contentType="video/x-ms-asf"; break;
case ".asf": contentType="video/x-ms-asf"; break;
case ".wm": contentType="video/x-ms-wm"; break;
case ".wmv": contentType="video/x-ms-wmv"; break;
case ".wmx": contentType="video/x-ms-wmx"; break;
default: contentType="Application/"+Path.GetExtension(fileSpec);break;
}
return contentType;
}
private string GetContentType(string fileSpec)
{
string contentType;
switch (Path.GetExtension(fileSpec))
{
case ".3gp": contentType="audio/AMR-WB-encrypted"; break;
case ".m4a": contentType="audio/m4a"; break;
case ".mid": contentType="audio/midi"; break;
case ".mp1": contentType="audio/mp1"; break;
case ".mp2": contentType="audio/mp2"; break;
case ".mp3": contentType="audio/mpeg"; break;
case ".m3u": contentType="audio/mpegurl"; break;
case ".mpga": contentType="audio/rn-mpeg"; break;
case ".pls": contentType="audio/scpls"; break;
case ".ra": contentType="audio/vnd.rn-realaudio"; break;
case ".wav": contentType="audio/wav"; break;
case ".aiff": contentType="audio/x-aiff"; break;
case ".wax": contentType="audio/x-ms-wax"; break;
case ".wma": contentType="audio/x-ms-wma"; break;
case ".aif": contentType="audio/x-pn-aiff"; break;
case ".au": contentType="audio/x-pn-au"; break;
case ".ram": contentType="audio/x-pn-realaudio"; break;
case ".rms": contentType="audio/x-realaudio-secure"; break;
case ".bmp": contentType="image/bmp"; break;
case ".gif": contentType="image/gif"; break;
case ".jpg": contentType="image/jpeg"; break;
case ".png": contentType="image/png"; break;
case ".tif": contentType="image/tiff"; break;
case ".rp": contentType="image/vnd.rn-realpix"; break;
case ".ico": contentType="image/x-icon"; break;
case ".xbm": contentType="image/x-xbitmap"; break;
case ".css": contentType="text/css"; break;
case ".htm": contentType="text/html"; break;
case ".uls": contentType="text/iuls"; break;
case ".txt": contentType="text/plain"; break;
case ".wsc": contentType="text/scriptlet"; break;
case ".rt": contentType="text/vnd.rn-realtext"; break;
case ".htt": contentType="text/webviewhtml"; break;
case ".htc": contentType="text/x-component"; break;
case ".vcf": contentType="text/x-vcard"; break;
case ".xml": contentType="text/xml"; break;
case ".3g2": contentType="video/3gpp2"; break;
case ".mpeg": contentType="video/mpeg"; break;
case ".avi": contentType="video/msvideo"; break;
case ".rv": contentType="video/vnd.rn-realvideo"; break;
case ".mpa": contentType="video/x-mpg"; break;
case ".asx": contentType="video/x-ms-asf"; break;
case ".asf": contentType="video/x-ms-asf"; break;
case ".wm": contentType="video/x-ms-wm"; break;
case ".wmv": contentType="video/x-ms-wmv"; break;
case ".wmx": contentType="video/x-ms-wmx"; break;
default: contentType="Application/"+Path.GetExtension(fileSpec);break;
}
return contentType;
}
才算是解决了问题,以后再遇到问题,在其中添加就可以了
我本来还想通过
Response.AddHeader "Content-Disposition", "attachment; filename="+fileName
来动态的设置文件名的,可是总是遇到乱码问题,最后只能作罢
posted on 2005-03-01 13:59 K_Reverter 阅读(212) 评论(0) 编辑 收藏 举报