日期:2014-05-17 浏览次数:20672 次
<a href="http://www.test.com/salary.doc">下载文档</a>
------解决方案--------------------
两种方法,前面相当于客户端链接,后面是服务器处理
<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();
}