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

M

mo

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

S. Justin Gengo

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


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

Stuart Irving

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


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???
 
B

blackstaronline.net

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,701
Latest member
XavierQ83

Latest Threads

Top