有的时候我们不想让用户直接在IE中打开已知类型的文件,比如Word,而希望能直接下载,这时候可用下面代码来替换Response.Redirect
Response.ContentType = "application/octet-stream";Response.AddHeader("Content-Disposition", "attachment;FileName="+YourFileName);Response.BinaryWrite((byte[])YourFileData.Rows[0]["AttachmentContent"]);Response.End();
补充一下。通常我喜欢把链接做成这样: <a href="download.aspx/hello.chm?fileid=12345">hello.chm</a> 这样客户端下载的时候默认是 hello.chm 这个名字的。
Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved. 闵涛 E_mail:admin@mintao.net(欢迎提供学习资源)
鄂公网安备 42011102001154号
站长:MinTao ICP备案号:鄂ICP备11006601号-18