2012-11-23 5 views
0

서버에서 클라이언트로 파일을 다운로드하려고 할 때 문제가 있습니다. 클릭하면 파일 저장 프롬프트가 나타나기도하지만 다운로드 할 파일을 가리 키지 않습니다. 오히려 내 aspx 페이지를 가리 킵니까? 즉, 다운로드하려는 파일을 다운로드하지 않지만 다운로드 링크가있는 페이지를 다운로드합니다. 내가 다운로드에 지정한 파일이 완전히 무시되는 경우/아무런 효과가 없기 때문에 정말 이상한 ... 그것은 보인다 거의 ...잘못된 파일이 서버에서 클라이언트로 다운로드 중입니다.

if (File.Exists(Server.MapPath(driversLocation + name + ".zip"))) 
{ 
    FileInfo fileInfo = new FileInfo(Server.MapPath(driversLocation) + name + ".zip"); 

    Response.Clear(); 
    Response.AddHeader("Content-Disposition", "inline;attachment; filename=" + name + ".zip"); 
    Response.AddHeader("Content-Length", fileInfo.Length.ToString()); 
    Response.ContentType = "application/download"; 
    Response.Flush(); 
    Response.TransmitFile(Server.MapPath(driversLocation) + name + ".zip"); 
    Response.End(); 
} 

어떤 도움을 주시면 감사하겠습니다!

답변

0

문제는 "인라인"이었습니다.

관련 게시물 : : Content-Disposition:What are the differences between "inline" and "attachment"?

FileInfo fileInfo = new FileInfo(Server.MapPath(driversLocation + name + ".zip")); 

if (fileInfo.Exists) 
{ 
    Response.Clear(); 
    Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name); 
    Response.AddHeader("Content-Length", fileInfo.Length.ToString()); 
    Response.ContentType = "application/x-zip-compressed"; 
    Response.TransmitFile(fileInfo.FullName); 
    Response.End(); 
} 
+0

덕분에 코드를보다 쉽게 ​​조정할 수있는 몇 가지 다른 것들을 읽을 수 있습니다! 그 트릭을 했어 : D 조 – Alen

관련 문제