PDA

View Full Version : downloading PDF file



unaltro2
Mar 10, 2011, 5:37 PM
Hello, i'm trying simply to perform a download wuth the following code, but the PDF reader, once the file is downloaded, says something like "the file is corrupted" and it does not open it. So, the code is:



<ext:Button ID="btnDoc1" runat="server" Flat="True" Text="Guida Operativa" Icon="PageWhiteText" >
<AjaxEvents >
<Click OnEvent="mydownload" IsUpload="true" FormID="form1">
<EventMask ShowMask="false" MinDelay="500" Msg="" />
<Confirmation ConfirmRequest="True" Title="Confirmation required..." Message=""></Confirmation>
</Click>
</AjaxEvents>
</ext:Button>


and server side ( on 'mydownload' method):



mypdfFilePath = (HttpContext.Current.Server.MapPath("~\Docs\Guida Operativa.pdf"))

HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ContentType = "Application/pdf"
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename = Guida Operativa.pdf")
HttpContext.Current.Response.AppendHeader("Content-Length", New FileInfo(mypdfFilePath).Length.ToString())
HttpContext.Current.Response.TransmitFile(HttpCont ext.Current.Server.MapPath(mypdfFilePath))
HttpContext.Current.Response.Close()
HttpContext.Current.Response.End()



with a classic asp.net button, it works; and the PDf file is not corrupted itself.

Anyone knows where i'm in fault?
Thanks in advance.

Fabio