C#如何时间文件下载?
发布网友
发布时间:2024-10-03 11:01
我来回答
共2个回答
热心网友
时间:2024-10-20 05:22
放置一个按钮,添加click代码,强制下载..如下:
protected void Button1_Click(object sender, EventArgs e)
{
//========不从缓存拿数据,直接下载服务器文件====================
string destFileName = Server.MapPath("file/" + this.Label1.Text.ToString().Trim());
FileInfo fi = new FileInfo(destFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(Path.GetFileName(destFileName)));
Response.AppendHeader("Content-Length", fi.Length.ToString());
Response.WriteFile(destFileName);
Response.Flush();
Response.End();
}
=================
将this.Label1.Text.ToString().Trim()改成你的文件名就可以了
热心网友
时间:2024-10-20 05:22
学习!