469,580 Members | 2,007 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,580 developers. It's quick & easy.

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

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

Apr 4 '06 #1
3 3086
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
<mo@novastar.net> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
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 '06 #2
Does the filename/path contain either "[" or "]" characters - if so, getting
rid of them may resolve the problem.
<mo@novastar.net> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
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 '06 #3
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

Apr 4 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Dorsa | last post: by
2 posts views Thread by ntm | last post: by
3 posts views Thread by Guy Penfold | last post: by
6 posts views Thread by aljosa.mohorovic | last post: by
3 posts views Thread by rafi | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.