C#如何實現下載文件保存到本地上面去


public void btnTemplate_Click(object sender, EventArgs e)
{

string strResult = string.Empty;
string strPath = Server.MapPath("~/uploadfile/");
string strFile = string.Format(@"{0}\{1}", strPath, "base.xls");

using (FileStream fs = new FileStream(strFile, FileMode.Open))
{
byte[] bytes = new byte[(int) fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("base.xlsx", System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
}
strPath:模板存放路徑


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM