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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pdf viewing in asp.net gives File Download window in the web server, b

Status
Not open for further replies.

svkumsani

Programmer
Feb 2, 2006
27
0
0
US
I am new to .net development and I am working on some reports where the user needs to have web printing option. Since the report requires column headers in all the pages, I have decided to use crystal reports instead of using window.print(). What I learned is to do web printing using crystal reports, I need to export it to pdf file and stream it to the user. Herewith I am providing the code I am using

'Dim oStream As New System.IO.MemoryStream

oRpt.SetDataSource(dt)
myExportFile = "c:\temp\" & Session.SessionID.ToString & ".pdf"


'Response.BinaryWrite(oXMLHttp.ResponseBody)

Response.WriteFile(myExportFile)
'Response.End()
'Response.WriteFile(myExportFile)
'Response.Redirect(myExportFile)
Response.Flush()
Response.Close()
System.IO.File.Delete(myExportFile)

The code works fine in my local pc, but it gives File download window showing Open, Save, Cancel option when I deploy it into a web server. I tried to launch my website using Firefox or Netscape Navigator, the website works fine. I am not sure what I am missing in my web server to make the IE work without showing the File Download window.

Your help will be greatly appreciated if anyone throw some light in this problem
 
I have a form, but I don't have a crystal viewer on it. I am using DataTable in my code. Can I use it or do I have to create a Dataset, do you have the sample code?
 
Based on what I am reading in the link you have provided, that is what I am using it in my code. Why am I still getting the error?
 
svkumsani said:
I have a form, but I don't have a crystal viewer on it.

you just said the above..so how are you following the instructions from the link I sent you?

read throught the document again and follow the steps.

 
what I meant was.. after I read the link, I have included crystal view on my form, but I am still getting the same error. But based on what I am seeing on the export button code, it doesn't require CR viewer. Correct me if I am wrong.
 
again...the export code only runs AFTER the report gets created period. did you follow the instructions??? or just add a viewer. follow the instrcutions and you will see what I mean.

 
I think the problem I have is for some reason the database connection is not happening between my dataset vs crystal reports. I tried to load the report using CRViewer and associated the dataset with it. But it is not showing any data and the same data which gets associated with a datagrid shows correctly. For some reason crystal reports created using ttx file is not getting associated with the data. Is there any alternative approach to use ttx file? or do you have any idea why am I not getting the database connection?

Here is the sample code
Public oRpt As New DailyVolMeterRpt

Dim dt As New DataTable
oRpt.Load()
dt = CType(Session("DV_Source"), DataTable)
oRpt.SetDataSource(dt)
CRViewer.ReportSource = oRpt
CRViewer.DataBind()
CRViewer.Visible = True

DailyVolMeterRpt is my crystal report file
 
Create a Dataset using the Wizard...OK, this will ensure your connection to the DB.

Create a BLANK aspx form and drop a CR Viewer on it.

Create a crystal report and use the Dataset as the reports source using the wizard. you should now see DB fields.

add these to your blank page with the viewer on it.

Imports CrystalDecisions
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Web
Imports CrystalDecisions.Shared

above your page load

Dim crReportDoc As New YourCRName

now on the form load I don't know how your connected to the DB or what type of DB your using or what.. but this should point you in the right direction..

Dim crDatabase As CrystalDecisions.CrystalReports.Engine.Database
Dim crTables As CrystalDecisions.CrystalReports.Engine.Tables
Dim crTable As CrystalDecisions.CrystalReports.Engine.Table

crDatabase = crReportDoc.Database
crTables = crDatabase.Tables
For Each crTable In crTables
crTable.SetDataSource(YourDataSetName)
Next

YourReportName.ReportSource = crReportDoc

ExportData(crReportDoc)

the exportdata runs the original sub I gave you...




 
I figured out the problem. Now I need to ask you a question. I have decided to use crystal reports using Crystal report viewer instead of using the Datagrid in my main page. The reason for that is to use the Find(search) option available in Crystal report viewer. For web, how do I make this event get fired when I type some text in the Find option. I see events for OnDrill and OnNavigate. But I don't see events for OnSearch. Does this feature disabled for web? Please let me know.
 
My question is when enter something in the Find dialog and click the binacular button. It is giving me some error, I feel that the Search event is not getting triggered. Here is the error message I am getting,

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:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
CrystalDecisions.Web.ReportAgent.q(Int32 H, String I, SearchDirection J) +62
CrystalDecisions.Web..<(String w, SearchDirection x) +133
CrystalDecisions.Web..3(CommandEventArgs l) +85
CrystalDecisions.Web..OnBubbleEvent(Object source, EventArgs e) +367
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +120
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +127
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292


 
I dont use the toolbar within the report. but I beleive that the search option only finds text that's already on the report.

you are using the toolbar correct?

or are you trying to create your own search on the same form as the viewer?

 
I am using the toolbar and trying to use the seach option from the toolbar.
 
I am using vs.net 2003 and crystal reports 9.0. The code works fine in my local machine, but when I try to deploy the code into a web server. I am getting Cannot find KeycodeV2.dll, or invalid keycode error. I have a web setup project where I included all the merge modules. I installed crytal 9.0 and .Net framework in the prod web server. Could anyone give me a solution to the problem. I have already deployed my code into dev web server where I have visual studio 2003 and crystal reports 9.0 installed already. Am I missing any installation files in the prod web server? When I searched in prod web server, I don't find any .msm files. Please let me know if you have any solutions to this problem.
 
did you follow the directions on the above link with the deployment of CR? you don't have to install CR on your server. you need to create a deployment project within your current project and then build the deployment project and INSTALL it onto your server. there are CR merge modules that need to get installed onto your server.

all the answers are in this thread.

 
Thanks dvannoy. How to install CR merge modules onto the server? Where do I find the installation file? I searched the hard drive in that prod web server, I didn't find any .msm files related CR. Please let me know. I did created a web project where I included all the msm modules specified in the pdf file you have given above and installed it in the web server.
 
hi Dvannoy, I want to ask you one more question. How to change a header value dynamically. Right now I am using parameter field for that. When the report loads first time, the parameter field value changes correctly. Basically what I am trying to do is, when user changes a date value in a calendar control, that value needs to get updated in the report header of a crystal report when the user hits the submit button. But once the report loaded into crystal report viewer, the parameter values which I am passing are not working(by pressing submit button). Do you have any idea of how to solve this problem. Thanks.
 
That is what I am doing. In my submit button, I am calling myreport.Load().
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top