downloading PDF file

  1. #1

    downloading PDF file

    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(HttpContext.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
    Last edited by unaltro2; Mar 10, 2011 at 5:41 PM.

Similar Threads

  1. Replies: 2
    Last Post: Aug 30, 2013, 1:48 AM
  2. Replies: 1
    Last Post: Nov 02, 2012, 4:07 AM
  3. [CLOSED] Downloading a file from a menu directEvent
    By feanor91 in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Jun 28, 2012, 7:19 AM
  4. [CLOSED] BADRESPONSE downloading a file
    By vadym.f in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Feb 24, 2012, 4:12 PM
  5. [CLOSED] DirectEvent from webService downloading file
    By pil0t in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 04, 2010, 6:05 AM

Posting Permissions