朋友问起怎么实现文件下载的功能。
实现之后贴出源码如下:

        private void downLoad(string filename)
        {
            
string path = Server.MapPath("download/")+filename;            
            FileInfo fi 
= new FileInfo(path);
            
if (fi.Exists)
            {
                Response.Clear();
                Response.AddHeader(
"Content-Disposition","attachment;filename="+Server.UrlEncode(filename));
                Response.AddHeader(
"Content-Length",fi.Length.ToString());                
                Response.ContentType 
= "application/octet-stream;charset=gb2321";
                Response.WriteFile(fi.FullName);                    
                Response.Flush(); 
                Response.Close();
            }
        }
posted on 2007-09-16 15:26  逐风者  阅读(9704)  评论(3编辑  收藏  举报