public void Download()
        {
            Response.ContentType = "application/x-zip-compressed";
            Response.AddHeader("Content-Disposition", "attachment;filename= 商品管理导入模板.xls");
            string FileName = Server.MapPath("..//..//Areas//LR_LGManager//Views//Product//商品管理导入模板.xlsx");
            Response.TransmitFile(FileName);            //Response.ContentType = "application/x-zip-compressed";
            //Response.AddHeader("Content-Disposition", "attachment;filename=商品管理导入模板.xlsx");
            //string filename = Server.MapPath("..//..//Areas//LR_LGManager//Views//Product//商品管理导入模板.xlsx");
            //Response.TransmitFile(filename);
        }

解决方案 »

  1.   

    我一般这样写的,或者直接url
    System.IO.FileStream FS = new FileStream(Server.MapPath("~/Web/ExcelTemplate/test.xlsx"), FileMode.Open, FileAccess.Read);
                BinaryReader BR = new BinaryReader(FS);
           
                System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + System.Web.HttpUtility.UrlPathEncode("test.xlsx"));
                System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("big5");
                //System.Web.HttpContext.Current.Response.Charset = "big5";
                //System.Web.HttpContext.Current.Response.Charset = "utf-8";
                //System.Web.HttpContext.Current.Response.Charset = "iso-8859-2";
                System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
                //System.Web.HttpContext.Current.Response.ContentType ="application/vnd.ms-excel";
                System.Web.HttpContext.Current.Response.BinaryWrite(BR.ReadBytes(Convert.ToInt32(FS.Length)));
                System.Web.HttpContext.Current.Response.Flush();
                System.Web.HttpContext.Current.Response.Close();
                System.Web.HttpContext.Current.Response.End();
      

  2.   


    我用的url地址才可以