Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal Report Exporting to Excel problem

Status
Not open for further replies.

mubaig75

Programmer
Sep 16, 2004
11
CA
I have an ASP.NET website where I am showing off crystal reports to users by exporting them to pdf format. Following is the code:
----------------
1 Private Sub ExportReport()
2 Dim oStream As System.IO.MemoryStream =
3 myReport.ExportToStream(
ExportFormatType.PortableDocFormat)

4 Response.Clear()
5 Response.Buffer() = True
6 Response.ContentType = "application/pdf"
7 Try
8 Response.BinaryWrite(oStream.ToArray())
9 Catch err As Exception
10 Response.Write("< BR >")
11 Response.Write(err.Message.ToString)
12 End Try
13 oStream.Close()
14 Response.End()
15 End Sub
-----------------------
This code working absolutely fine. But if I want to export the reports to EXCEL format then I just need to change lines 3 and 6:

3 ==> myReport.ExportToStream(
ExportFormatType.Excel)

6 ==> Response.ContentType = "application/vnd.ms-excel"

After the above alterations the should work fine but it doesn't. I even tried to export to MS Word but it didn't work as well. Following is the explaination what actually happening:

So after user clicks View Report, what happening is the excel application opens in the browser but showing no report just saying : "You are curently not logged in.
Please Log in first!". This is kind of weird to me because this message only comes when somebody tries to access my website's any page without Logging In. So to find out whats going wrong I put a break point at Page_Init procedure. So I step through each line and just after executing Response.End() statement I found that the page loads itself and as result of that it breaks again at Page_Init procedure. But as I am checking at the begining whether user is logged in or not and apparently when this page gets
executed 2nd time, it doesn't have any session information thus resulting "You are curently not logged in. Please Log in first!" message but displays in the excel application opened in the browser. One more thing I also
observed that whenever I clicked to get the report, I always see a small window appearing for very short period of time at the top left corner with a progress bar stating "Transfering...
I really don't know whats causing this twice execution because it only happens when I try to export cystal report to some MS Office format such as MS Excel.

I also tried to put trace on and there I also confirmed it that this page is
getting executed twice in case of exporting to Excel format. Exporting to
PDF works perfect.

I would really really appreciate your help.

thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top