[csharp]
//引用
using System.IO;
//button事件
protected void Button3_Click(object sender, EventArgs e)
{
string fileName = "123.jpg";//客戶端保存的文件名
string filePath = Server.MapPath("images/1.jpg");//路徑
//以字符流的形式
下載文件
FileStream fs = new FileStream(
filePath, 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(fileName, System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點(diǎn)擊舉報(bào)。