Hello,
Generating report through passing parameter to Crystal Report,i need to open the report in PDF in new window on button click, i tried the following code
getting "Missing Parameter" Error
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
sysMonthRpt = New ReportDocument
sysMonthRpt.Load(Server.MapPath("SystemStatus.rpt"))
sysMonthRpt.SetDatabaseLogon("sa", "", "myServer", "myDB")
CrystalReportViewer1.ReportSource = sysMonthRpt
Dim myParams As New ParameterFields
Dim myparam As New ParameterField
Dim myDiscretevalue As New ParameterDiscreteValue
myparam.ParameterFieldName = "@tkMonth"
myDiscretevalue.Value = "12"
myparam.CurrentValues.Add(myDiscretevalue)
myParams.Add(myparam)
CrystalReportViewer1.ParameterFieldInfo = myParams
Dim oStream As MemoryStream
' using System.IO
oStream = DirectCast(sysMonthRpt.ExportToStream(CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat), MemoryStream)
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/pdf"
Response.BinaryWrite(oStream.ToArray())
Response.[End]()
End Sub
Any solution plz..
Thanks
Regards,
Bahru
MCP (Microsoft Certified Professional) - ASP.NET
MCTS (Microsoft Certified Technology Specialist) - SQL Sever
I dn't want to use the Display toolbar for exporting, i need in PDF as default, so that im writing manually. I'm getting the result in CrystalReport but i need to open in PDF without selecting (without "Missing Parameter" error), im searching for long, i can't
find any proper solution...
any idea
Thanks
Regards,
Bahru
MCP (Microsoft Certified Professional) - ASP.NET
MCTS (Microsoft Certified Technology Specialist) - SQL Sever
I dn't want to use the Display toolbar for exporting, i need in PDF as default, so that im writing manually. I'm getting the result in CrystalReport but i need to open in PDF without selecting (without "Missing Parameter" error), im searching for long, i can't
find any proper solution...
any idea
Thanks
Regards,
Bahru
MCP (Microsoft Certified Professional) - ASP.NET
MCTS (Microsoft Certified Technology Specialist) - SQL Sever
No luck Waqar.. i need to open the PDF atleast in browser, i got some code, but its opening in same window,then i can't access the application if its open in the same window!!..
one more thing also, i need to pass parameter as well? any idea?
Regards,
Bahru
MCP (Microsoft Certified Professional) - ASP.NET
MCTS (Microsoft Certified Technology Specialist) - SQL Sever
This Post is quite old and I am sure the answer has been found, But I still wanted to post how Crystal Report can be displayed in PDF on a button click.
Public Overrides Sub Button1_click(ByVal sender
AsObject,
ByVal args
As System.EventArgs)
deenindia
Member
46 Points
101 Posts
Open the crystal report in PDF on button click
Dec 30, 2009 08:16 AM|LINK
Hello,
Generating report through passing parameter to Crystal Report,i need to open the report in PDF in new window on button click, i tried the following code
getting "Missing Parameter" Error
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
sysMonthRpt = New ReportDocument
sysMonthRpt.Load(Server.MapPath("SystemStatus.rpt"))
sysMonthRpt.SetDatabaseLogon("sa", "", "myServer", "myDB")
CrystalReportViewer1.ReportSource = sysMonthRpt
Dim myParams As New ParameterFields
Dim myparam As New ParameterField
Dim myDiscretevalue As New ParameterDiscreteValue
myparam.ParameterFieldName = "@tkMonth"
myDiscretevalue.Value = "12"
myparam.CurrentValues.Add(myDiscretevalue)
myParams.Add(myparam)
CrystalReportViewer1.ParameterFieldInfo = myParams
Dim oStream As MemoryStream
' using System.IO
oStream = DirectCast(sysMonthRpt.ExportToStream(CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat), MemoryStream)
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/pdf"
Response.BinaryWrite(oStream.ToArray())
Response.[End]()
End Sub
Any solution plz..
Thanks
Bahru
MCP (Microsoft Certified Professional) - ASP.NET
MCTS (Microsoft Certified Technology Specialist) - SQL Sever
Waqar_ali
Contributor
3325 Points
693 Posts
Re: Open the crystal report in PDF on button click
Dec 30, 2009 08:47 AM|LINK
Crystal report has this functionality by default. Why you are doing it manually?
Software Engineer
Please mark as answer if it help you.
asprabahar
Member
158 Points
85 Posts
Re: Open the crystal report in PDF on button click
Dec 30, 2009 09:19 AM|LINK
Hi deenindia
use this
ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='JavaScript'> window.open('RptCrystalViewer.aspx? "fName=" + "" + "','','width=800,height=450,scrollbars=1,resizable=1,status=1'); </script>");
in the pafe load event
if there is file name in fName do this process
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/vnd.ms-excel"; //
application/pdf //
text/richtext
Response.WriteFile(<Report Path > + <file name>);
Response.Flush();
Response.Close();
But the Best Solution is to user Crystal report Viewer so that you can export to different format ,
crysta report
Prabakar Samiyappan
Is this your answer "Mark as Answer"
deenindia
Member
46 Points
101 Posts
Re: Open the crystal report in PDF on button click
Dec 31, 2009 03:46 AM|LINK
Thanx for your reply
I dn't want to use the Display toolbar for exporting, i need in PDF as default, so that im writing manually. I'm getting the result in CrystalReport but i need to open in PDF without selecting (without "Missing Parameter" error), im searching for long, i can't find any proper solution...
any idea
Thanks
Bahru
MCP (Microsoft Certified Professional) - ASP.NET
MCTS (Microsoft Certified Technology Specialist) - SQL Sever
deenindia
Member
46 Points
101 Posts
Re: Open the crystal report in PDF on button click
Dec 31, 2009 03:50 AM|LINK
Thanx for your reply
I dn't want to use the Display toolbar for exporting, i need in PDF as default, so that im writing manually. I'm getting the result in CrystalReport but i need to open in PDF without selecting (without "Missing Parameter" error), im searching for long, i can't find any proper solution...
any idea
Thanks
Bahru
MCP (Microsoft Certified Professional) - ASP.NET
MCTS (Microsoft Certified Technology Specialist) - SQL Sever
Waqar_ali
Contributor
3325 Points
693 Posts
Re: Open the crystal report in PDF on button click
Dec 31, 2009 04:38 AM|LINK
In the following links same examples implemented as you want. try these and let me know wheter it help you or not.
http://www.mahipalreddy.com/cr/crarticle1.htm
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=1503&lngWId=10
Software Engineer
Please mark as answer if it help you.
deenindia
Member
46 Points
101 Posts
Re: Open the crystal report in PDF on button click
Jan 03, 2010 02:50 AM|LINK
No luck Waqar.. i need to open the PDF atleast in browser, i got some code, but its opening in same window,then i can't access the application if its open in the same window!!..
one more thing also, i need to pass parameter as well? any idea?
Bahru
MCP (Microsoft Certified Professional) - ASP.NET
MCTS (Microsoft Certified Technology Specialist) - SQL Sever
pragya163
Member
2 Points
1 Post
Re: Open the crystal report in PDF on button click
Feb 12, 2013 01:27 PM|LINK
This Post is quite old and I am sure the answer has been found, But I still wanted to post how Crystal Report can be displayed in PDF on a button click.
Public Overrides Sub Button1_click(ByVal sender As Object, ByVal args As System.EventArgs)
Try
DbUtils.StartTransaction()
Dim crReport As New ReportDocument
crReport.Load(Me.Page.Server.MapPath(BaseClasses.Configuration.ApplicationSettings.Current.AppRootPath) & "Reports\JobTrackingAll.rpt")
ls_filter ="{tabel/viewinCrystalreport.Field}='{" & the value you want to pass & "}'"
crReport.RecordSelectionFormula = ls_filter //if you have multiple filters use this format
DisplayReportAsPDF(crReport)
Catch ex As Exception
Utils.RegisterJScriptAlert(Me.Page, "Error", ex.Message)
DbUtils.RollBackTransaction()
Finally
DbUtils.EndTransaction()
End Try
End Sub
-- To display the report to PDF
Private Sub DisplayReportAsPDF(ByVal reportObject As ReportDocument)
Dim dbTable As CrystalDecisions.CrystalReports.Engine.Table
Dim dbLogin As CrystalDecisions.Shared.TableLogOnInfo
Dim crExportOptions As ExportOptions
Dim crDiskFileDestinationOptions As DiskFileDestinationOptions
Dim dir As New DirectoryInfo(Me.Page.Server.MapPath(BaseClasses.Configuration.ApplicationSettings.Current.AppRootPath) & "Reports\")
Dim Files As New List(Of FileInfo)
Files.AddRange(dir.GetFiles)
Files = Files.FindAll(Function(f As FileInfo) f.Extension.ToLower = ".xls" OrElse f.Extension.ToLower = ".pdf")
For Each delfile As FileInfo In Files
If delfile.CreationTime.Date < Now.Date Then
delfile.Delete()
End If
Next
Dim fileName As String
Dim redirect As String
fileName =Me.Page.Server.MapPath(BaseClasses.Configuration.ApplicationSettings.Current.AppRootPath) & "Reports\" & Now.Hour.ToString & Now.Minute.ToString & Now.Second.ToString & Now.Millisecond.ToString & ".pdf"
redirect ="../Reports/" & fileName.Substring(fileName.LastIndexOf("\") + 1)
crDiskFileDestinationOptions =New DiskFileDestinationOptions
crExportOptions = reportObject.ExportOptions
With crExportOptions
.DestinationOptions = crDiskFileDestinationOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
End With
Dim ReportAccess As UserTable = UserTable.Instance
Dim DBConnectionName As String = ReportAccess.ConnectionName
Dim DBConnectionString As String = BaseClasses.Configuration.ApplicationSettings.Current.GetConnectionString(DBConnectionName)
Dim DBConnection As BaseClasses.Configuration.DatabaseConnection
DBConnection = BaseClasses.Configuration.DatabaseConnection.Parse(DBConnectionName, DBConnectionString)
Dim dbConnectionInfo As New ConnectionInfo
' get the DB Connection's UserID , Password, Server Name, and Database Name
Dim UserID As String = DBConnection.UserName
Dim Pwd As String = DBConnection.Password
Dim dbServer As String = DBConnection.DatabaseServer
Dim dbName As String = DBConnection.DatabaseName
With dbConnectionInfo
.ServerName = dbServer
.DatabaseName = dbName
.UserID = UserID
.Password = Pwd
End With
'Login to all the tables in the report
For Each dbTable In reportObject.Database.Tables
dbLogin = dbTable.LogOnInfo
dbLogin.ConnectionInfo = dbConnectionInfo
dbTable.ApplyLogOnInfo(dbLogin)
Next
reportObject.Refresh()
reportObject.Export()
reportObject.Close()
reportObject.Dispose()
Me.Page.Response.Clear()
Me.Page.Response.ContentType = "application/pdf"
Me.Page.Response.AddHeader("Content-Disposition", "attachment; filename=" & fileName.Substring(fileName.LastIndexOf("\") + 1))
Me.Page.Response.WriteFile(redirect)
Me.Page.Response.Flush()
Me.Page.Response.Close()
End Sub