代码改变世界

[导入]如何制作邮箱附件下载

2006-11-10 20:34  迷路中的路人甲  阅读(742)  评论(6编辑  收藏  举报

   string fileurl="xx.htm";

   string xurl=Server.MapPath("/userfiles/"+fileurl.ToString());
   System.IO.FileInfo file = new System.IO.FileInfo(xurl);
   if(file.Exists)
   {
    Response.Clear();
    Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
    Response.AddHeader("Content-Length", file.Length.ToString());
    Response.ContentType = "application/octet-stream";
    Response.Filter.Close();
    Response.WriteFile(file.FullName);              
    Response.End();
   }
   else
   {
    Response.Write("文件不存在");
    Response.End();
   }


文章来源:http://blog.163.com/asd119_cn/blog/static/11973332006101083359201