2013-10-29 4 views
0

내 응용 프로그램에 내보내기 기능이 추가되었습니다. 그것은 아주 잘 작동합니다. 이제 내보내기 기능을 완료 한 후 자동 다운로드 기능을 추가하고 싶습니다. using C# asp.net다운로드 기능을 추가하는 방법

+0

시도한 사항이 있습니까? 어떤 코드라도? –

답변

0

다음을 수행 할 수 있습니다. 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(); 

    } 
0

이 스크립트를 추가하십시오.

<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']); 
?> 
관련 문제