我在我的应用程序中添加了导出功能。它工作得很好。现在我想在完成导出功能后添加自动下载功能。使用c# asp.net
发布于 2013-10-29 15:12:05
可以通过以下方式实现: string file = "";
file = "Path of File Name to Download";
if (file != "")
{
context.Response.Clear();
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("content-disposition", "attachment;filename=" + Path.GetFileName(file));
context.Response.WriteFile(file);
context.Response.End();
}发布于 2013-10-29 19:07:41
添加此脚本。
<script type="text/javascript">
function populateIframe(id,path)
{
var ifrm = document.getElementById(id);
ifrm.src = "download.php?path="+path;
}
</script>把它放在你想要的下载按钮的位置(这里我们只用了一个链接):
<iframe id="frame1" style="display:none"></iframe>
<a href="javascript:populateIframe('frame1','<?php echo $path; ?>')">download</a>文件'download.php‘(需要放在你的服务器上)只包含:
<?php
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=".$_GET['path']);
readfile($_GET['path']);
?>https://stackoverflow.com/questions/19651485
复制相似问题