asp.net 2.0 开发的一个网站,有一个查看文档按钮,点击此按钮,会自动下载网站根目录下的一个word文档,并且文档的内容在IE中直接打开,请问怎么实现吗?最好是有代码的
解决方案 »
- VS2008編輯gridview獲取不到文本框的值
- url重写问题,急
- 有谁知道DataTable跨行跨列啊
- 请问一个系统中要同时用bs和cs该怎么实现?
- 如何实现在窗体页双击自定义控件后,在代码页中生成“控件ID_Click(object sender, EventArgs e)”事件?!
- 求教如何转送NavigateUrl="~/detailnews.aspx"+'<%# Eval("NewsTitle") %>' 参数
- UrlDecode和UrlEncode有什么区别??
- 可否提供Object-Relational Mapping的例子?
- 新手问题 跪求解决
- 关于treeview
- 水晶报表列显示不全的问题
- 关于客户端填充gridview
path = Server.MapPath(path) + "\\12349088 郑玲.doc";
FileInfo fi = new FileInfo(path);
if (fi.Exists)
{
Response.Clear();
Response.Write(fi.Name);
Response.AddHeader("Content-Disposition", "inline;filename=" + Server.UrlEncode(path)); Response.AddHeader("Content-Length", fi.Length.ToString());
//添加输出流
Response.ContentType = "application/octet-stream";
Response.Filter.Close();
Response.WriteFile(fi.FullName); Response.End();
}
这样的代码,运行后,还是会出来下载保存对话框,如何解决呢?
这是因为你的 ContentType 写错了。
Response.ContentType = "application/octet-stream";不支持word文档吗?因为之前就用的这条语句,是可以下载word文档的。非得要改成下面这个吗?Response.ContentType = "application/msword";