WEB下载小文件

来源:互联网 发布:谭浩强c语言入门第四版 编辑:程序博客网 时间:2024/05/01 09:51

     // Response.ContentType = "application/x-rar-compressed";
   Export("application/ms-excel", filename ); //注意文件一类型
filename//为路径
 private void Export(string FileType, string FileName)
        {
            Response.Charset = "GB2312";
            Response.ContentEncoding = System.Text.Encoding.UTF7;
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
            Response.ContentType = FileType;
            this.EnableViewState = false;
          StringWriter tw = new StringWriter();
           // HtmlTextWriter hw = new HtmlTextWriter(tw);
          //  GridView1.RenderControl(hw);
            Response.Write(tw.ToString());
            Response.End();
           
        }