angrymeeow
Programmer
Hi there,
I have a project (written in asp.net 2003 c#, using the bundled version of crystal) that is primarily used to view, print and export (to PDF and Excel) reports . Everything works 100% on my development machine and on a test machine at my client, but some people are getting errors when trying to export to excel (but not to PDF). They get the following error "Object reference not set to an instance of an object".
Below is the event that exports the report to Excel. Please note that I am exporting to the browser.
[red]G[/red][purple]r[/purple][blue]r[/blue][green]r[/green][yellow].[/yellow][white]..[/white][yellow]m[/yellow][green]e[/green][blue]e[/blue][purple]o[/purple][red]w[/red]![[cat2] [cat2] [cat2]](/data/assets/smilies/cat2.gif)
I have a project (written in asp.net 2003 c#, using the bundled version of crystal) that is primarily used to view, print and export (to PDF and Excel) reports . Everything works 100% on my development machine and on a test machine at my client, but some people are getting errors when trying to export to excel (but not to PDF). They get the following error "Object reference not set to an instance of an object".
Below is the event that exports the report to Excel. Please note that I am exporting to the browser.
Code:
private void cmdExcel_Click(object sender, System.EventArgs e)
{
try
{
string ReportName = ReportServer.Business.Settings.GetReportName (this.Session) + " " + DateTime.Today.ToString("dd-MMM-yyyy");
ExportOptions exp = new ExportOptions();
exp.ExportFormatType = ExportFormatType.Excel;
exp.FormatOptions = new ExcelFormatOptions();
ExportRequestContext req = new ExportRequestContex();
req.ExportInfo = exp;
System.IO.Stream st;
st = this.reportDocument1.FormatEngine.ExportToStream(req);
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "application/xls";
Response.AddHeader("Content-Disposition", "filename="+ ReportName + ".xls");
byte[] b = new byte[st.Length];
st.Read(b,0,(int) st.Length);
Response.BinaryWrite(b);
Response.End();
}
catch (System.Exception excep)
{
this.lblErrorMessage.Text = excep.Message.ToString();
}
}
[red]G[/red][purple]r[/purple][blue]r[/blue][green]r[/green][yellow].[/yellow][white]..[/white][yellow]m[/yellow][green]e[/green][blue]e[/blue][purple]o[/purple][red]w[/red]
![[cat2] [cat2] [cat2]](/data/assets/smilies/cat2.gif)