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);
}
uj5u.com熱心網友回復:
斷點進去看看,檢查路徑是否寫對了uj5u.com熱心網友回復:
解決了,換了個別的方法,這種方法實作不了uj5u.com熱心網友回復:
我一般這樣寫的,或者直接urlSystem.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();
uj5u.com熱心網友回復:
我用的url地址才可以
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/96244.html
標籤:ASP.NET
