c# 点按钮弹出下载框 我要在页面上有个按钮,一点击,会弹出下载对话框,文件在服务器上,要下载到客户端。最好有代码。谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 protected void Button1_Click(object sender, EventArgs e) { Response.AppendHeader("Content-Disposition", "attachment;filename=File.doc"); //输出内容的编码方式 Response.ContentEncoding = Encoding.UTF7; FileStream fs = new FileStream("d:/api.doc",FileMode.Open); BinaryReader br = new BinaryReader(fs); byte[] docbyte=br.ReadBytes(1000); while (docbyte.Length > 0) { Response.BinaryWrite(docbyte); docbyte = br.ReadBytes(1000); } Response.Flush(); Response.Close(); Response.End(); } /// <summary> /// 從WEB頁面文件下載 /// </summary> /// <param name="strFile">要下載的文件的絕對路徑</param> public static void DownloadFile(string strFile) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = "application/octet-stream"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode(Path.GetFileName(strFile).Trim()) + "\""); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.WriteFile(strFile); HttpContext.Current.Response.End(); } <input type="button" value="Try it." onclick="btn_click();"><script>function btn_click(){ window.open("../FileDownload.html?FileName=FuckJP.mp3");}</script> 有空看看,http://www.cnblogs.com/jiangshaofen/archive/2007/04/16/715227.html 怎么获取当前时间 格式为20130105 使用 get/set 属性向私有字段赋值遇到问题,求助 我想把这个数组拆开分组 1,2,3,4,5,6,7 怎么用js来实现啊? Coolite.Ext.Web.MenuItem 动态添加 item 想购买这个asp.net通用权限系统,想请前辈帮我把把脉!先感谢了! 为什么只能只执行一次,该怎么解决! 请教下高手 下面的代码哪里有错误 C#操作活动目录,映射网络磁盘的问题 关于水晶报表中数字不能够显示的问题? 请问Cint在哪个名称空间内,查了很长时间没有查到 急!请大家多帮忙,datagridview问题 存储过程
{
Response.AppendHeader("Content-Disposition", "attachment;filename=File.doc");
//输出内容的编码方式
Response.ContentEncoding = Encoding.UTF7; FileStream fs = new FileStream("d:/api.doc",FileMode.Open); BinaryReader br = new BinaryReader(fs); byte[] docbyte=br.ReadBytes(1000); while (docbyte.Length > 0)
{
Response.BinaryWrite(docbyte);
docbyte = br.ReadBytes(1000);
}
Response.Flush();
Response.Close();
Response.End();
}
/// 從WEB頁面文件下載
/// </summary>
/// <param name="strFile">要下載的文件的絕對路徑</param>
public static void DownloadFile(string strFile)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode(Path.GetFileName(strFile).Trim()) + "\"");
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.WriteFile(strFile);
HttpContext.Current.Response.End();
}
<input type="button" value="Try it." onclick="btn_click();">
<script>
function btn_click()
{
window.open("../FileDownload.html?FileName=FuckJP.mp3");
}
</script>