How to call a crystal report from asp.net?

anand

Regular
Joined
Jan 29, 2003
Messages
76
Location
chicago
Hi Friends
I am new to asp.net..i have a small doubt..i have a static report(.pdf)..there is a link labled as view report..when i click that link i want to display the report...pls let me know how to do that??here the problem os the enduser dont have crystal reports in thier system..just they have Browser(IE)..when the user clicks the link they have to download the .PDF report from the webserver and they have to display that in browser..pls give me a idea how to download the .pdf report from webserver and how to display that on browser.........
Thanks
satya
gummadilli@hotmail.com
 
Do you want to display a PDF document or a Crystal report? PDF's will only display if the user has something like Adobe Acrobat, whilst you can get a report to display within the browser.

John
 
Hi I want to display the .PDF report which was created by crystal reports...the end user dont have crystal reports in his system..he may have acrobat reader...while click the link in the webpage the report should be downloaded from the server and displayed in the browser..pls give me a idea??

pls tell me abt both ..pdf reports and crystal reports..how to display crystal report and how to display pdf report on browser..
Thanks
satya
 
A simple hyperlink to the PDF will open it, however it will be upto the user if they wish to view it in their browser or want to save it.

Crystal reports can be viewed with the CrystalReportsViewer web control. Its probably better if you read the help from Microsoft and Crystal Decisions on setting this up.

John
 
Hi friend
i was trying to link the pdf file from my webpage..when i clicked the link the acobat reader is opened and its reading the pdf file and its opened in browser..pls tell me what i have to do if it has to open immediatly.when i clicked that link....
or assume the end user dont have acrobat reader..in this situation what we have to do...pls give me a idea ..its very urgent...
Thanks
Anand
 
If you want to have the file always load in the browser then a PDF document isn't what you want. Adobe Acrobat will have to open for it to be readable.

It sounds like you will need to install the Crystal objects onto your server and load the report, this will be viewable by anybody as it is produced by the server - no addins necessary on the client.

A quick overview of adding the report to document is:
1 - Add a CrystalReportViewer control to a new web form.
2 - Add the report to your Project.
3 - Add a Report Document to your web form and select the report needed from the dropdown list.
4 - Point your link to this document and it should load the report inside a Crystal View on the webpage.

Sorry, I'm not going to explain setting up the server as it will be easier to follow the help within VS.net.

John
 
You could try to simply load the report document, including passing it the appropriate parameter values if it has any, and once that's done, try exporting the document as a .pdf file. Then, you have the option of saving it to the user's hard disk, displaying the report in Acrobat Reader, or both. Here's a small bit of code that might get you going in the right direction:

==============================================
*** Exporting ****

private dFileDOpts as New DiskFileDestinationOptions()
private eOpts as New ExportOptions()
private eFile as string

'Select a new filepath and name for the exported file
eFile = "C:\\" & <your report name>

'Indicate the exported file info to the DiskFileDestinationOptions
'variable
dFileDOpts.DiskFileName = eFile

eOpts = rptDoc.ExportOptions
eOpts.DestinationOptions = dFileDOpts
eOpts.ExportDestinationType = ExportDestinationType.DiskFile

Select Case eFormat
Case ".pdf"
eOpts.ExportFormatType = _
ExportFormatType.PortableDocFormat
Case ".xls"
eOpts.ExportFormatType = ExportFormatType.Excel
End Select

rptDoc.Export()


*** Displaying the export file in Acrobat Reader ***

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.WriteFile(eFile)
Response.Flush()
Response.Close()

===========================================

Hope this helps a little. :D
 
Hi friend
Lot of thanks for your help..now i know how to export crystal report to another formats such as .pdf/.xsl/.html/.doc/.rtf...its fine..but i am getting another error

i created a .xsl report from crystal report..when i am going to open that .xsl from excel its giving the error like "Unable to open the file..invalid character found in that file"..and i am getting the error to export the crystal report as .html file..pls let me know whats my mistake.....

Thanks
Anand
 
hi i used the following code to export report..pls tell me whats my mistake...

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Dim rpt As New CrystalReport1()

Dim dopt As New CrystalDecisions.Shared.DiskFileDestinationOptions()

rpt.ExportOptions.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile

rpt.ExportOptions.ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.Excel

'its working properly

'dopt.DiskFileName = "c:\studrpt.doc"

'its giving error

dopt.DiskFileName = "c:\studrpt1.xsl"

'its working properly

'dopt.DiskFileName = "c:\studrpt.rtf"

'its working properly

' dopt.DiskFileName = "c:\studrpt.pdf"

rpt.ExportOptions.DestinationOptions = dopt

rpt.Export()

End Sub

when i run the application its working properly..and its creating a .xsl file as c:\studrpt1.xsl my problem is when i am going to open this XSL file from excel its giving the following error



An invalid character was found in text content. Error processing resource 'file:///C:/studrpt1.xsl'.




pls tell me whats my mistake.....



Thank you
Satya
gummadi009@yahoo.com
 
anand:
It sounds like there is an issue with the content of the exported file. In other words, perhaps there's something inside of the Crystal report so that when you export it, Excel has a difficult time translating what that information is s'posed to be. Try to run your export routine against a different Crystal report with less content, and see if you get the same error. If not, then it's the orig. report that's the problem; if so, then there's another issue that is not standing out to me either. (BTW, you do mean a .xls file, and not a .xsl file, right? B/C, there could be your problem right there...just had to ask...) Hope this suggestion helps you out. I'm new to Crystal in VS.NET too, and I'm still learning just like yourself. :D
 
Hi Daspoo
Nice to hear form you agin..really i am a stupid guy..i did a small mistake in the bellow line of code
dopt.DiskFileName = "c:\studrpt1.xsl"


there i have to give the extension .xls instead of xsl..then it is working proplerly....

and i am getting error while exporting the report tio html

rpt.ExportOptions.ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.HTML40
dopt.DiskFileName = "c:\studrpt1.html"


pls let me know my mistake

Thank you
Satya/anand
 
anand:
Nah, you're not stupid. If that were true, I might be King of the all...heh...so what is the error message exactly that you are getting when you attempt to export the file? Is it the same:

An invalid character was found in text content. Error processing resource 'file:///C:/studrpt1.html'.
 
Hi Daspoo
Nice to hear from you.. i exported to xls... ..now thats working properly..but its not exporting to html format....pls let me know whats my mistake...


Thank you
Anand
 
Anand:
What's the exact error message you get when you try to export to HTML? And also, exactly where in code do you get the error (as in, what is the last line of code run before you get the error message(s))? Once we figure out what it's trying to tell us, we'll go from there.
 
Hi I am getting the following error(in line 126) while exporting to html

Server Error in '/anand/pdfreport2' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 124:
Line 125: rpt.ExportOptions.DestinationOptions = dopt
Line 126: rpt.Export()
Line 127: End Sub
Line 128:


Source File: C:\anand\pdfreport2\WebForm1.aspx.vb Line: 126

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
CrystalDecisions.Shared.HTMLFormatOptions.get_HTMLEnableSeparatedPages()
CrystalDecisions.CrystalReports.Engine.V..ctor(FormatEngine formatEngine, ExportRequestContext requestContext)
CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext)
CrystalDecisions.CrystalReports.Engine.FormatEngine.Export()
CrystalDecisions.CrystalReports.Engine.ReportDocument.Export()
pdfreport2.WebForm1.Button3_Click(Object sender, EventArgs e) in C:\anand\pdfreport2\WebForm1.aspx.vb:126
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.0.3705.0; ASP.NET Version:1.0.3705.0






my code is
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim rpt As New CrystalReport1()
Dim dopt As New CrystalDecisions.Shared.DiskFileDestinationOptions()
rpt.ExportOptions.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
rpt.ExportOptions.ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.HTML40



'its working properly
'dopt.DiskFileName = "c:\studrpt.doc"

'its giving error
dopt.DiskFileName = "c:\studrpt1.html"

'its working properly
'dopt.DiskFileName = "c:\studrpt.rtf"

'its working properly
' dopt.DiskFileName = "c:\studrpt.pdf"

rpt.ExportOptions.DestinationOptions = dopt
rpt.Export()
End Sub

pls let me know whats my mistake...
Thanks
Anand
 
Anand:
Man, I was WAY off! I tried this in my own exporting routine, and I got the same error message you did. So, I did a search in .NET for "export HTML" and I came up with the following code. When I used it, I didn't receive the error anymore. Hope this helps. Although, after running the code, I couldn't find the .html file on my machine ANYWHERE...(just a heads-up):

==========================================
Private Sub Button3_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button3_Click

Dim rpt As New CrystalReport1()
Dim dopt As
New CrystalDecisions.Shared.DiskFileDestinationOptions()
*** Dim htmlOpts As New HTMLFormatOptions()

*** ' Set the HTML format options.
*** htmlOpts.HTMLFileName = "c:\studrpt1.html"
*** htmlOpts.HTMLEnableSeparatedPages = <true or false>
*** htmlOpts.HTMLHasPageNavigator = <true or false>
*** rpt.ExportOptions.FormatOptions = htmlOpts

rpt.ExportOptions.ExportDestinationType =
CrystalDecisions.[Shared].ExportDestinationType.DiskFile
rpt.ExportOptions.ExportFormatType =
CrystalDecisions.[Shared].ExportFormatType.HTML40

dopt.DiskFileName = "c:\studrpt1.html"

rpt.exportOptions.DestinationOptions = dopt

rpt.Export()

End Sub
=============================================
Hope this helps!
 
Anand:
I'm not sure if you're still working on this issue or not, but I just found something today that might be the answer you're looking for. In my last post, I indicated that I got the HTML export to work without an error being generated, but that I didn't get an output HTML file following the export. Well, I found out why...

In the section of the previous post where I'm setting "HTML Format Options", one thing that needs to be set there is "HTMLBaseFolderName" for the HTMLFormatOptions object.

In other words, not only do you have to set the ".HTMLFileName", ".HTMLEnableSeparatedPages", and ".HTMLHasPageNavigator", but you also have to set ".HTMLBaseFolderName", which is basically where the exported HTML file will reside. You have to specify this property, because not only does the exported file exist in that folder, but also any images which are contained in the exported file.

So, if you were exporting your file to HTML, your code would look something like this (based on the previous post):
=============================================
Private Sub Button3_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Button3_Click

Dim rpt As New CrystalReport1()
Dim dopt As
New CrystalDecisions.Shared.DiskFileDestinationOptions()
Dim htmlOpts As New HTMLFormatOptions()

' Set the HTML format options.
With htmlOpts
.HTMLFileName = "studrpt1.html" <exclude the file path>
.HTMLBaseFolderName = "C:\"
.HTMLEnableSeparatedPages = <true or false>
.HTMLHasPageNavigator = <true or false>
End With

rpt.ExportOptions.FormatOptions = htmlOpts

rpt.ExportOptions.ExportDestinationType =
CrystalDecisions.[Shared].ExportDestinationType.DiskFile
rpt.ExportOptions.ExportFormatType =
CrystalDecisions.[Shared].ExportFormatType.HTML40

dopt.DiskFileName = "c:\studrpt1.html"

rpt.exportOptions.DestinationOptions = dopt

rpt.Export()

End Sub
=============================================

The above code will then export the file (studrpt1.html) to the path: "c:\studrpt\" and within that folder will be the studrpt1.html file, as well as a folder "Images" which will contain any images embedded in the pre-exported report document. Whew!

If you have any questions about this, Crystal Decisions provides a pretty good example of how the code looks and works. Just follow the link:
http://support.crystaldecisions.com/updates/default.asp, and within the filename textbox, enter "vbnet_web_export.exe". Hope all of my rambling helps! :D
 
Hi Daspoo
Can u pls tell me how to create a Crystal report from XML file....pls send a small example ..or tell me what steps i have to follow to generate report from XML file in .Net..............
Thank you
Anand
 
Anand:
Soory my man. You're on your own there. I'm not educated in the "art" of XML. I barely am understanding this Crystal stuff. heh...Seriously, I'm sure if you hunt around Crystal Decisions website or their forums, you'll find something or someone that will be able to help. Good luck! :cool:
 
Exporting Crystal Report in HTML format in .net

Hi ,

I could able to Export the Crystal Report in HTML format .But it create a HTML file in different temp folder. I want to open the file on the click of button . I could i export the file in some Specific folder rather than ot's own temp folder. Could any body help me . Thanks.
 
Back
Top