File download - 'save' works, 'open' cannot find file

Discussion in 'ASP .Net' started by mo@novastar.net, Apr 4, 2006.

  1. Guest

    I have an application that uses Reporting Services. When the user
    chooses to print a report, they are taken to a window that allows them
    to fill in parameters for the report. They then click a button to
    either export to PDF or to EXCEL. Once the report is generated, the
    byte array containing the data is put into session and an aspx page is
    loaded into a hidded iframe that "prints" the report (using the byte
    array from session) causing the file download dialog to appear. If you

    choose "save", everything is fine - the report saves correctly. If you

    choose "open", the file "cannot be found" either in Excel or
    Acrobat/PDF.

    If I skip the iframe, using the same page to print the report that is
    used to select the params, everything works fine. I am baffled...!


    Code to follow:


    /* BEGIN Report Parameter Selector Page */
    private void ibtnPDF_Click(object sender,
    System.Web.UI.ImageClickEventArgs e)
    {
    /* CODE LEFT OUT FOR SIMPLICITY */


    rb = new SQLReportBuilder( parameterCount );
    rb.ReportName = reportName;
    rb.ReportPath = reportDirectory;
    rb.SetRenderingFormat( SQLReportBuilder.ReportFormat.PDF );


    LoadReport();



    }


    private void LoadReport()
    {
    string encoding = null;
    string mimeType = null;
    string[] streamIDs = null;
    Warning[] warnings = null;
    ParameterValue[] usedParams = null;

    /* CODE LEFT OUT FOR SIMPLICITY */


    byte[] result = rs.Render( rb.ReportPath + rb.ReportName,
    rb.Format, rb.HistoryID, rb.DeviceInfo, rb.Parameters,
    rb.DataSourceCredentials, rb.ShowHideToggle, out encoding, out
    mimeType, out usedParams, out warnings, out streamIDs );


    Session["__REPORTDATA"] = result;
    Session["__OUTPUTFILENAME"] = reportName + rb.ReportFileExtension;



    this.iframeReportDownload.Attributes.Add( "src",
    "ReportDownloader.aspx" );


    }


    /* END Report Parameter Selector Page */

    /* BEGIN Report Printing Page (ReportDownloader.aspx)*/
    byte[] result = null;
    string outputFileName = null;


    private void Page_Load(object sender, System.EventArgs e)
    {
    result = (byte[])Session["__REPORTDATA"];
    outputFileName = (string)Session[ "__OUTPUTFILENAME" ];


    if ( result != null )
    {
    PrintReport();
    }



    }


    private void PrintReport()
    {
    Response.Buffer = true;
    Response.Clear();
    Response.ContentType = "application/octet-stream";
    Response.AddHeader( "Content-Disposition", "attachment; filename="

    + outputFileName );
    Response.AddHeader( "Content-Length", result.Length.ToString() );
    Response.BinaryWrite( result );
    Response.Flush();
    Response.End();

    }


    /* END Report Printing Page */

    If I put the exact code that is in the PrintReport() function into the
    LoadReport() function, in place of the line
    "this.iframeReportDownload.Attributes.Add( "src",
    "ReportDownloader.aspx" );" - it works just fine - I can save and open.



    Does anyone know why I cannot open the file but I can save the file???
    , Apr 4, 2006
    #1
    1. Advertising

  2. mo,

    This isn't really a solution to your particular problem, but what about just
    opening the report in a new window?

    Regards,

    --
    S. Justin Gengo
    Web Developer / Programmer

    Free code library:
    http://www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche


    <> wrote in message
    news:...
    >I have an application that uses Reporting Services. When the user
    > chooses to print a report, they are taken to a window that allows them
    > to fill in parameters for the report. They then click a button to
    > either export to PDF or to EXCEL. Once the report is generated, the
    > byte array containing the data is put into session and an aspx page is
    > loaded into a hidded iframe that "prints" the report (using the byte
    > array from session) causing the file download dialog to appear. If you
    >
    > choose "save", everything is fine - the report saves correctly. If you
    >
    > choose "open", the file "cannot be found" either in Excel or
    > Acrobat/PDF.
    >
    > If I skip the iframe, using the same page to print the report that is
    > used to select the params, everything works fine. I am baffled...!
    >
    >
    > Code to follow:
    >
    >
    > /* BEGIN Report Parameter Selector Page */
    > private void ibtnPDF_Click(object sender,
    > System.Web.UI.ImageClickEventArgs e)
    > {
    > /* CODE LEFT OUT FOR SIMPLICITY */
    >
    >
    > rb = new SQLReportBuilder( parameterCount );
    > rb.ReportName = reportName;
    > rb.ReportPath = reportDirectory;
    > rb.SetRenderingFormat( SQLReportBuilder.ReportFormat.PDF );
    >
    >
    > LoadReport();
    >
    >
    >
    > }
    >
    >
    > private void LoadReport()
    > {
    > string encoding = null;
    > string mimeType = null;
    > string[] streamIDs = null;
    > Warning[] warnings = null;
    > ParameterValue[] usedParams = null;
    >
    > /* CODE LEFT OUT FOR SIMPLICITY */
    >
    >
    > byte[] result = rs.Render( rb.ReportPath + rb.ReportName,
    > rb.Format, rb.HistoryID, rb.DeviceInfo, rb.Parameters,
    > rb.DataSourceCredentials, rb.ShowHideToggle, out encoding, out
    > mimeType, out usedParams, out warnings, out streamIDs );
    >
    >
    > Session["__REPORTDATA"] = result;
    > Session["__OUTPUTFILENAME"] = reportName + rb.ReportFileExtension;
    >
    >
    >
    > this.iframeReportDownload.Attributes.Add( "src",
    > "ReportDownloader.aspx" );
    >
    >
    > }
    >
    >
    > /* END Report Parameter Selector Page */
    >
    > /* BEGIN Report Printing Page (ReportDownloader.aspx)*/
    > byte[] result = null;
    > string outputFileName = null;
    >
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > result = (byte[])Session["__REPORTDATA"];
    > outputFileName = (string)Session[ "__OUTPUTFILENAME" ];
    >
    >
    > if ( result != null )
    > {
    > PrintReport();
    > }
    >
    >
    >
    > }
    >
    >
    > private void PrintReport()
    > {
    > Response.Buffer = true;
    > Response.Clear();
    > Response.ContentType = "application/octet-stream";
    > Response.AddHeader( "Content-Disposition", "attachment; filename="
    >
    > + outputFileName );
    > Response.AddHeader( "Content-Length", result.Length.ToString() );
    > Response.BinaryWrite( result );
    > Response.Flush();
    > Response.End();
    >
    > }
    >
    >
    > /* END Report Printing Page */
    >
    > If I put the exact code that is in the PrintReport() function into the
    > LoadReport() function, in place of the line
    > "this.iframeReportDownload.Attributes.Add( "src",
    > "ReportDownloader.aspx" );" - it works just fine - I can save and open.
    >
    >
    >
    > Does anyone know why I cannot open the file but I can save the file???
    >
    S. Justin Gengo, Apr 4, 2006
    #2
    1. Advertising

  3. Does the filename/path contain either "[" or "]" characters - if so, getting
    rid of them may resolve the problem.


    <> wrote in message
    news:...
    >I have an application that uses Reporting Services. When the user
    > chooses to print a report, they are taken to a window that allows them
    > to fill in parameters for the report. They then click a button to
    > either export to PDF or to EXCEL. Once the report is generated, the
    > byte array containing the data is put into session and an aspx page is
    > loaded into a hidded iframe that "prints" the report (using the byte
    > array from session) causing the file download dialog to appear. If you
    >
    > choose "save", everything is fine - the report saves correctly. If you
    >
    > choose "open", the file "cannot be found" either in Excel or
    > Acrobat/PDF.
    >
    > If I skip the iframe, using the same page to print the report that is
    > used to select the params, everything works fine. I am baffled...!
    >
    >
    > Code to follow:
    >
    >
    > /* BEGIN Report Parameter Selector Page */
    > private void ibtnPDF_Click(object sender,
    > System.Web.UI.ImageClickEventArgs e)
    > {
    > /* CODE LEFT OUT FOR SIMPLICITY */
    >
    >
    > rb = new SQLReportBuilder( parameterCount );
    > rb.ReportName = reportName;
    > rb.ReportPath = reportDirectory;
    > rb.SetRenderingFormat( SQLReportBuilder.ReportFormat.PDF );
    >
    >
    > LoadReport();
    >
    >
    >
    > }
    >
    >
    > private void LoadReport()
    > {
    > string encoding = null;
    > string mimeType = null;
    > string[] streamIDs = null;
    > Warning[] warnings = null;
    > ParameterValue[] usedParams = null;
    >
    > /* CODE LEFT OUT FOR SIMPLICITY */
    >
    >
    > byte[] result = rs.Render( rb.ReportPath + rb.ReportName,
    > rb.Format, rb.HistoryID, rb.DeviceInfo, rb.Parameters,
    > rb.DataSourceCredentials, rb.ShowHideToggle, out encoding, out
    > mimeType, out usedParams, out warnings, out streamIDs );
    >
    >
    > Session["__REPORTDATA"] = result;
    > Session["__OUTPUTFILENAME"] = reportName + rb.ReportFileExtension;
    >
    >
    >
    > this.iframeReportDownload.Attributes.Add( "src",
    > "ReportDownloader.aspx" );
    >
    >
    > }
    >
    >
    > /* END Report Parameter Selector Page */
    >
    > /* BEGIN Report Printing Page (ReportDownloader.aspx)*/
    > byte[] result = null;
    > string outputFileName = null;
    >
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > result = (byte[])Session["__REPORTDATA"];
    > outputFileName = (string)Session[ "__OUTPUTFILENAME" ];
    >
    >
    > if ( result != null )
    > {
    > PrintReport();
    > }
    >
    >
    >
    > }
    >
    >
    > private void PrintReport()
    > {
    > Response.Buffer = true;
    > Response.Clear();
    > Response.ContentType = "application/octet-stream";
    > Response.AddHeader( "Content-Disposition", "attachment; filename="
    >
    > + outputFileName );
    > Response.AddHeader( "Content-Length", result.Length.ToString() );
    > Response.BinaryWrite( result );
    > Response.Flush();
    > Response.End();
    >
    > }
    >
    >
    > /* END Report Printing Page */
    >
    > If I put the exact code that is in the PrintReport() function into the
    > LoadReport() function, in place of the line
    > "this.iframeReportDownload.Attributes.Add( "src",
    > "ReportDownloader.aspx" );" - it works just fine - I can save and open.
    >
    >
    >
    > Does anyone know why I cannot open the file but I can save the file???
    >
    Stuart Irving, Apr 4, 2006
    #3
  4. There seems to be a problem with opening excel from an iframe window.

    I had the same problem when I turned on 'SmartNavigation' which one of
    its features is putting your entire page into a hidden iframe. The
    minute that happened I could no longer 'OPEN' from my export to Excel
    feature, but 'SAVE' continued to work fine.

    I turned 'OFF' smart navigation on that page and now everything works
    fine again. Try creating a workaround so you don't have to use the
    hidden iframe on your .net page. I bet it will work fine if you get rid
    of that iframe.

    Hope it helps,
    Jeremy Reid
    http://hgtit.com
    blackstaronline.net, Apr 4, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. BusyBoy
    Replies:
    2
    Views:
    600
    =?Utf-8?B?TGVvbiBNYXluZQ==?=
    Oct 31, 2006
  2. tiewknvc9
    Replies:
    12
    Views:
    1,271
    Chris Uppal
    Feb 19, 2007
  3. chandan
    Replies:
    0
    Views:
    969
    chandan
    Nov 17, 2008
  4. chandan
    Replies:
    0
    Views:
    511
    chandan
    Nov 17, 2008
  5. Michael
    Replies:
    0
    Views:
    229
    Michael
    Jan 25, 2005
Loading...

Share This Page