日期:2014-05-17  浏览次数:20672 次

下载word文档如何不在页面中打开
服务器有个word文档,下载以后打开是在网页中打开的,如何实现不再页面中打开word?
我用Response.Redirect(pathdownload);//pathdownload是下载的路径

------解决方案--------------------
<a href="pathdownload">word文档文档下载</a>
注意pathdownload要类似于 http://www.***.com/0/file.doc
------解决方案--------------------
HTML code

<a href="http://www.test.com/salary.doc">下载文档</a>

------解决方案--------------------
两种方法,前面相当于客户端链接,后面是服务器处理
HTML code
<a href="aaa.doc">下载文档</a>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

------解决方案--------------------
用客户端链接就可以了,注意路径
<a href="word.doc">word文档下载 </a>
------解决方案--------------------
protected void Button1_Click(object sender, EventArgs e)
{
FileStream fileStream = new FileStream(Server.MapPath("abc.doc"), FileMode.Open);
long fileSize = fileStream.Length;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + HttpUtility.UrlEncode("abc.doc", System.Text.Encoding.UTF8) + "\"");
Response.AddHeader("Content-Length", fileSize.ToString());
byte[] fileBuffer = new byte[fileSize];
fileStream.Read(fileBuffer, 0, (int)fileSize);
fileStream.Close();
Response.BinaryWrite(fileBuffer);
Response.End(); 
}