473,385 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How is it possible ...

....... that nobody knows the answer.
I can't imagine that I am the only one that uses parameters in CR.

So, my question again:

I have the following problem.
(VB.NET 2003 with CR)

I have a report with a multiple-value discrete value and a rangevalue.
The report shows fine in the viewer, but when I hit the export to pdf
button, it only uses one of two discrete values.

This is the code:
Dim BeginPeriode As String
Dim EindPeriode As String

BeginPeriode = Request.QueryString("BeginPeriode")
EindPeriode = Request.QueryString("EindPeriode")

Dim myReport As New RapportAIRCOStoringen

Dim paramFields As New ParameterFields
Dim paramField As New ParameterField
Dim discreteVal As New ParameterDiscreteValue
Dim rangeVal As New ParameterRangeValue

paramField.ParameterFieldName = "FiliaalKeuze"
discreteVal.Value = "2044"
paramField.CurrentValues.Add(discreteVal)

discreteVal = New ParameterDiscreteValue
discreteVal.Value = "2344"
paramField.CurrentValues.Add(discreteVal)

paramFields.Add(paramField)

paramField = New ParameterField

paramField.ParameterFieldName = "Periode"

rangeVal.StartValue = BeginPeriode
rangeVal.EndValue = EindPeriode
paramField.CurrentValues.Add(rangeVal)

paramFields.Add(paramField)

crViewer.ParameterFieldInfo = paramFields
myReport.SetParameterValue("Periode", rangeVal)
myReport.SetParameterValue("FiliaalKeuze", discreteVal)
crViewer.ReportSource = myReport

As you can see I use myReport.SetParameterValue to feed the pdf.
It goes wrong with the discrete value. It only sees the second value I
entered and not the first.
How can I get this going?
Kind regards,
Alison


Feb 16 '06 #1
13 2504
Wow, you do all that for Crystal Reports? What is RapportAIRCOStoringen?
Here is all I do for CR

Dim x As CrystalDecisions.CrystalReports.Engine.ReportDocum ent

x.Load(sReportPath)
'Reports are not embedded resources
x.SetParameterValue("Paramater1", Paramaters(1)) 'Dynamic Paramaters
x.SetParameterValue("Paramater2", Paramaters(2))
x.SetDataSource(mydata) 'Strongly
Typed Datasets

Me.CrystalReportViewer1.ReportSource = x
Me.CrystalReportViewer1.PrintReport()
'Now to answer your question about your code, hmm

Ok, first

Never --> Dim x as new object
'This is silly, lazy and unprofessional. So if you are in high
school, keep the course.
Instead --> Dim x as object
Set x = new object
'Reserve your space and contract
'Then make use of it.

I think this is your problem

myReport.SetParameterValue("FiliaalKeuze", discreteVal)

Why are you setting the crView paramaters and the myReport paramaters?
-->crViewer.ParameterFieldInfo = paramFields
-->myReport.SetParameterValue("Periode", rangeVal)

I think that myReport is the only think that needs to be set
I had to spent time reading your code to understand what you were doing.

Here is an attempt to clean it up.

Private Sub TestIT()

Dim myReport As RapportAIRCOStoringen
Dim paramFields As ParameterFields
Dim paramField As ParameterField

Dim BeginPeriode As String
Dim EindPeriode As String

'Todo wrap everything in try
paramFields = New ParameterFields

Try
BeginPeriode = Request.QueryString("BeginPeriode")
EindPeriode = Request.QueryString("EindPeriode")
Catch ex As Exception
Dim exCustom As ApplicationException
exCustom = New ApplicationException("Unable to parse Query
Paramaters.", ex)
Throw exCustom
End Try

'Todo wrap in try
paramField = CreateParamater("FiliaalKeuze")
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2044))
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2344))
myReport.SetParameterValue("FiliaalKeuze", paramField)
'paramFields.Add(paramField) --> Not needed

'Todo wrap in try
paramField = CreateParamater("Periode")
paramField.CurrentValues.Add(CreateParameterRangeV alue(BeginPeriode,
EindPeriode))
myReport.SetParameterValue("Periode", paramField)
'paramFields.Add(paramField)--> Not needed

'Todo wrap in try, i don't think you need this
'myReport.SetParameterValue("Periode", rangeVal)
'myReport.SetParameterValue("FiliaalKeuze", discreteVal)

'Todo, determine if we need this step; I don't think you do
'crViewer.ParameterFieldInfo = paramFields

crViewer.ReportSource = myReport

End Sub

Private Function CreateParamater(ByVal ParamaterName As String) As
ParameterField
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParamaterName

Return paramField

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As Object,
ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function

"Alison Givens" <in**@cross-it.nl> wrote in message
news:eW*************@TK2MSFTNGP11.phx.gbl...
...... that nobody knows the answer.
I can't imagine that I am the only one that uses parameters in CR.

So, my question again:

I have the following problem.
(VB.NET 2003 with CR)

I have a report with a multiple-value discrete value and a rangevalue.
The report shows fine in the viewer, but when I hit the export to pdf
button, it only uses one of two discrete values.

This is the code:
Dim BeginPeriode As String
Dim EindPeriode As String

BeginPeriode = Request.QueryString("BeginPeriode")
EindPeriode = Request.QueryString("EindPeriode")

Dim myReport As New RapportAIRCOStoringen

Dim paramFields As New ParameterFields
Dim paramField As New ParameterField
Dim discreteVal As New ParameterDiscreteValue
Dim rangeVal As New ParameterRangeValue

paramField.ParameterFieldName = "FiliaalKeuze"
discreteVal.Value = "2044"
paramField.CurrentValues.Add(discreteVal)

discreteVal = New ParameterDiscreteValue
discreteVal.Value = "2344"
paramField.CurrentValues.Add(discreteVal)

paramFields.Add(paramField)

paramField = New ParameterField

paramField.ParameterFieldName = "Periode"

rangeVal.StartValue = BeginPeriode
rangeVal.EndValue = EindPeriode
paramField.CurrentValues.Add(rangeVal)

paramFields.Add(paramField)

crViewer.ParameterFieldInfo = paramFields
myReport.SetParameterValue("Periode", rangeVal)
myReport.SetParameterValue("FiliaalKeuze", discreteVal)
crViewer.ReportSource = myReport

As you can see I use myReport.SetParameterValue to feed the pdf.
It goes wrong with the discrete value. It only sees the second value I
entered and not the first.
How can I get this going?
Kind regards,
Alison

Feb 16 '06 #2
When I use your solution I get blue lines under the text like this

paramField = CreateParamater("FiliaalKeuze")
The text is:
Value of type '1 dimensional array of
CrystalDecisions.Shared.ParameterField' cannot be converted
to 'Crystal.Decisions.Shared.ParameterField'

Return paramField
The text is:
Value of type 'CrystalDecisions.Shared.ParameterField' cannot be converted
to '1 dimensional array of Crystal.Decisions.Shared.ParameterField'

Same for
paramField = CreateParamater("Periode")
Return paramDiscreteValue

Any idea what causes this?

Alison
"AMDRIT" <am****@hotmail.com> wrote in message
news:ur*************@TK2MSFTNGP14.phx.gbl...
Wow, you do all that for Crystal Reports? What is RapportAIRCOStoringen?
Here is all I do for CR

Dim x As CrystalDecisions.CrystalReports.Engine.ReportDocum ent

x.Load(sReportPath) 'Reports are not embedded resources
x.SetParameterValue("Paramater1", Paramaters(1)) 'Dynamic Paramaters
x.SetParameterValue("Paramater2", Paramaters(2))
x.SetDataSource(mydata)
'Strongly Typed Datasets

Me.CrystalReportViewer1.ReportSource = x
Me.CrystalReportViewer1.PrintReport()
'Now to answer your question about your code, hmm

Ok, first

Never --> Dim x as new object
'This is silly, lazy and unprofessional. So if you are in high
school, keep the course.
Instead --> Dim x as object
Set x = new object
'Reserve your space and contract
'Then make use of it.

I think this is your problem

myReport.SetParameterValue("FiliaalKeuze", discreteVal)

Why are you setting the crView paramaters and the myReport paramaters?
-->crViewer.ParameterFieldInfo = paramFields
-->myReport.SetParameterValue("Periode", rangeVal)

I think that myReport is the only think that needs to be set
I had to spent time reading your code to understand what you were doing.

Here is an attempt to clean it up.

Private Sub TestIT()

Dim myReport As RapportAIRCOStoringen
Dim paramFields As ParameterFields
Dim paramField As ParameterField

Dim BeginPeriode As String
Dim EindPeriode As String

'Todo wrap everything in try
paramFields = New ParameterFields

Try
BeginPeriode = Request.QueryString("BeginPeriode")
EindPeriode = Request.QueryString("EindPeriode")
Catch ex As Exception
Dim exCustom As ApplicationException
exCustom = New ApplicationException("Unable to parse Query
Paramaters.", ex)
Throw exCustom
End Try

'Todo wrap in try
paramField = CreateParamater("FiliaalKeuze")
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2044))
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2344))
myReport.SetParameterValue("FiliaalKeuze", paramField)
'paramFields.Add(paramField) --> Not needed

'Todo wrap in try
paramField = CreateParamater("Periode")
paramField.CurrentValues.Add(CreateParameterRangeV alue(BeginPeriode,
EindPeriode))
myReport.SetParameterValue("Periode", paramField)
'paramFields.Add(paramField)--> Not needed

'Todo wrap in try, i don't think you need this
'myReport.SetParameterValue("Periode", rangeVal)
'myReport.SetParameterValue("FiliaalKeuze", discreteVal)

'Todo, determine if we need this step; I don't think you do
'crViewer.ParameterFieldInfo = paramFields

crViewer.ReportSource = myReport

End Sub

Private Function CreateParamater(ByVal ParamaterName As String) As
ParameterField
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParamaterName

Return paramField

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As Object,
ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function

"Alison Givens" <in**@cross-it.nl> wrote in message
news:eW*************@TK2MSFTNGP11.phx.gbl...
...... that nobody knows the answer.
I can't imagine that I am the only one that uses parameters in CR.

So, my question again:

I have the following problem.
(VB.NET 2003 with CR)

I have a report with a multiple-value discrete value and a rangevalue.
The report shows fine in the viewer, but when I hit the export to pdf
button, it only uses one of two discrete values.

This is the code:
Dim BeginPeriode As String
Dim EindPeriode As String

BeginPeriode = Request.QueryString("BeginPeriode")
EindPeriode = Request.QueryString("EindPeriode")

Dim myReport As New RapportAIRCOStoringen

Dim paramFields As New ParameterFields
Dim paramField As New ParameterField
Dim discreteVal As New ParameterDiscreteValue
Dim rangeVal As New ParameterRangeValue

paramField.ParameterFieldName = "FiliaalKeuze"
discreteVal.Value = "2044"
paramField.CurrentValues.Add(discreteVal)

discreteVal = New ParameterDiscreteValue
discreteVal.Value = "2344"
paramField.CurrentValues.Add(discreteVal)

paramFields.Add(paramField)

paramField = New ParameterField

paramField.ParameterFieldName = "Periode"

rangeVal.StartValue = BeginPeriode
rangeVal.EndValue = EindPeriode
paramField.CurrentValues.Add(rangeVal)

paramFields.Add(paramField)

crViewer.ParameterFieldInfo = paramFields
myReport.SetParameterValue("Periode", rangeVal)
myReport.SetParameterValue("FiliaalKeuze", discreteVal)
crViewer.ReportSource = myReport

As you can see I use myReport.SetParameterValue to feed the pdf.
It goes wrong with the discrete value. It only sees the second value I
entered and not the first.
How can I get this going?
Kind regards,
Alison


Feb 20 '06 #3
All I did was take your code and break it up. I haven't tested the code,
rather; I was just breaking up your code for readability.

You had:

Dim paramField As New ParameterField
paramField = New ParameterField
paramField.ParameterFieldName = "Periode"

I changed to (I don't see a difference):

paramField = CreateParamater("Periode")

Private Function CreateParamater(ByVal ParamaterName As String) As
ParameterField
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParamaterName

Return paramField

End Function

Perhaps you could share your resulting code for comparison? Did you see
that I suggested the error in your code was

myReport.SetParameterValue("FiliaalKeuze", discreteVal) 'You only call this
statement once (Effectively 2344) but you wanted two values.
"Alison Givens" <in**@cross-it.nl> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
When I use your solution I get blue lines under the text like this

paramField = CreateParamater("FiliaalKeuze")
The text is:
Value of type '1 dimensional array of
CrystalDecisions.Shared.ParameterField' cannot be converted
to 'Crystal.Decisions.Shared.ParameterField'

Return paramField
The text is:
Value of type 'CrystalDecisions.Shared.ParameterField' cannot be converted
to '1 dimensional array of Crystal.Decisions.Shared.ParameterField'

Same for
paramField = CreateParamater("Periode")
Return paramDiscreteValue

Any idea what causes this?

Alison
"AMDRIT" <am****@hotmail.com> wrote in message
news:ur*************@TK2MSFTNGP14.phx.gbl...
Wow, you do all that for Crystal Reports? What is RapportAIRCOStoringen?
Here is all I do for CR

Dim x As CrystalDecisions.CrystalReports.Engine.ReportDocum ent

x.Load(sReportPath) 'Reports are not embedded resources
x.SetParameterValue("Paramater1", Paramaters(1)) 'Dynamic Paramaters
x.SetParameterValue("Paramater2", Paramaters(2))
x.SetDataSource(mydata) 'Strongly Typed Datasets

Me.CrystalReportViewer1.ReportSource = x
Me.CrystalReportViewer1.PrintReport()
'Now to answer your question about your code, hmm

Ok, first

Never --> Dim x as new object
'This is silly, lazy and unprofessional. So if you are in high
school, keep the course.
Instead --> Dim x as object
Set x = new object
'Reserve your space and contract
'Then make use of it.

I think this is your problem

myReport.SetParameterValue("FiliaalKeuze", discreteVal)

Why are you setting the crView paramaters and the myReport paramaters?
-->crViewer.ParameterFieldInfo = paramFields
-->myReport.SetParameterValue("Periode", rangeVal)

I think that myReport is the only think that needs to be set
I had to spent time reading your code to understand what you were doing.

Here is an attempt to clean it up.

Private Sub TestIT()

Dim myReport As RapportAIRCOStoringen
Dim paramFields As ParameterFields
Dim paramField As ParameterField

Dim BeginPeriode As String
Dim EindPeriode As String

'Todo wrap everything in try
paramFields = New ParameterFields

Try
BeginPeriode = Request.QueryString("BeginPeriode")
EindPeriode = Request.QueryString("EindPeriode")
Catch ex As Exception
Dim exCustom As ApplicationException
exCustom = New ApplicationException("Unable to parse Query
Paramaters.", ex)
Throw exCustom
End Try

'Todo wrap in try
paramField = CreateParamater("FiliaalKeuze")
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2044))
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2344))
myReport.SetParameterValue("FiliaalKeuze", paramField)
'paramFields.Add(paramField) --> Not needed

'Todo wrap in try
paramField = CreateParamater("Periode")
paramField.CurrentValues.Add(CreateParameterRangeV alue(BeginPeriode,
EindPeriode))
myReport.SetParameterValue("Periode", paramField)
'paramFields.Add(paramField)--> Not needed

'Todo wrap in try, i don't think you need this
'myReport.SetParameterValue("Periode", rangeVal)
'myReport.SetParameterValue("FiliaalKeuze", discreteVal)

'Todo, determine if we need this step; I don't think you do
'crViewer.ParameterFieldInfo = paramFields

crViewer.ReportSource = myReport

End Sub

Private Function CreateParamater(ByVal ParamaterName As String) As
ParameterField
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParamaterName

Return paramField

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As Object,
ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function

"Alison Givens" <in**@cross-it.nl> wrote in message
news:eW*************@TK2MSFTNGP11.phx.gbl...
...... that nobody knows the answer.
I can't imagine that I am the only one that uses parameters in CR.

So, my question again:

I have the following problem.
(VB.NET 2003 with CR)

I have a report with a multiple-value discrete value and a rangevalue.
The report shows fine in the viewer, but when I hit the export to pdf
button, it only uses one of two discrete values.

This is the code:
Dim BeginPeriode As String
Dim EindPeriode As String

BeginPeriode = Request.QueryString("BeginPeriode")
EindPeriode = Request.QueryString("EindPeriode")

Dim myReport As New RapportAIRCOStoringen

Dim paramFields As New ParameterFields
Dim paramField As New ParameterField
Dim discreteVal As New ParameterDiscreteValue
Dim rangeVal As New ParameterRangeValue

paramField.ParameterFieldName = "FiliaalKeuze"
discreteVal.Value = "2044"
paramField.CurrentValues.Add(discreteVal)

discreteVal = New ParameterDiscreteValue
discreteVal.Value = "2344"
paramField.CurrentValues.Add(discreteVal)

paramFields.Add(paramField)

paramField = New ParameterField

paramField.ParameterFieldName = "Periode"

rangeVal.StartValue = BeginPeriode
rangeVal.EndValue = EindPeriode
paramField.CurrentValues.Add(rangeVal)

paramFields.Add(paramField)

crViewer.ParameterFieldInfo = paramFields
myReport.SetParameterValue("Periode", rangeVal)
myReport.SetParameterValue("FiliaalKeuze", discreteVal)
crViewer.ReportSource = myReport

As you can see I use myReport.SetParameterValue to feed the pdf.
It goes wrong with the discrete value. It only sees the second value I
entered and not the first.
How can I get this going?
Kind regards,
Alison



Feb 20 '06 #4
> Perhaps you could share your resulting code for comparison? Did you see
that I suggested the error in your code was

myReport.SetParameterValue("FiliaalKeuze", discreteVal) 'You only call
this statement once (Effectively 2344) but you wanted two values.
To get the thing going, it would be enough for me at first to know how to
call the statement twice, so the other value is forwarded too.
(btw, these two values will be SessionObjects two, but I did it hardcoded
for testing)
Best would be ofcourse that I learn to do it 'clean' of course. I am a real
newbee at this.

Here is the rest of my code:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.CrystalReports.Engine.ReportDocum ent
Imports CrystalDecisions.Shared
Imports System.IO
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()

Dim myReport As RapportAIRCOStoringen
Dim paramFields As ParameterFields
Dim paramField As ParameterField

Dim BeginPeriode As String
Dim EindPeriode As String

'Todo wrap everything in try
paramFields = New ParameterFields

Try
BeginPeriode = Request.QueryString("BeginPeriode")
EindPeriode = Request.QueryString("EindPeriode")
Catch ex As Exception
Dim exCustom As ApplicationException
exCustom = New ApplicationException("Unable to parse Query
Paramaters.", ex)
Throw exCustom
End Try

'Todo wrap in try
paramField = CreateParameter("FiliaalKeuze")
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2044))
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2344))
myReport.SetParameterValue("FiliaalKeuze", paramField)
'Todo wrap in try
paramField = CreateParameter("Periode")
paramField.CurrentValues.Add(CreateParameterRangeV alue(BeginPeriode,
EindPeriode))
myReport.SetParameterValue("Periode", paramField)
crViewer.ReportSource = myReport
'exporteren to pdf
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
Dim myDiskFileDestinationOptions As
CrystalDecisions.Shared.DiskFileDestinationOptions
Dim myExportFile As String

myExportFile = "\\192.168.2.106\syn2sql$\PDF_" &
Session.SessionID.ToString & ".pdf"
myDiskFileDestinationOptions = New
CrystalDecisions.Shared.DiskFileDestinationOptions
myDiskFileDestinationOptions.DiskFileName = myExportFile
myExportOptions = myReport.ExportOptions
With myExportOptions
.DestinationOptions = myDiskFileDestinationOptions
.ExportDestinationType = .ExportDestinationType.DiskFile
.ExportFormatType = .ExportFormatType.PortableDocFormat
End With

Try
myReport.Export()
Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try

Session("exportbestand") = myExportFile
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

Response.WriteFile(myExportFile)
Response.Flush()
Response.Close()

System.IO.File.Delete(myExportFile)
End Sub

Private Function CreateParameter(ByVal ParameterName As String) As
ParameterField()
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParameterName

'Return paramField

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue()

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

'Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As Object,
ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function
Private Sub cmdEerste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEerste.Click
crViewer.ShowFirstPage()
End Sub

Private Sub cmdLaatste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdLaatste.Click
crViewer.ShowLastPage()
End Sub

Private Sub cmdTerug_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdTerug.Click
crViewer.ShowPreviousPage()
End Sub

Private Sub cmdVerder_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdVerder.Click
crViewer.ShowNextPage()
End Sub

Private Sub drpZoom_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles drpZoom.SelectedIndexChanged
crViewer.Zoom(drpZoom.SelectedItem.Value)
End Sub
Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload
Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

System.IO.File.Delete(myExportFile)
End Sub
End Class


"Alison Givens" <in**@cross-it.nl> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
When I use your solution I get blue lines under the text like this

paramField = CreateParamater("FiliaalKeuze")
The text is:
Value of type '1 dimensional array of
CrystalDecisions.Shared.ParameterField' cannot be converted
to 'Crystal.Decisions.Shared.ParameterField'

Return paramField
The text is:
Value of type 'CrystalDecisions.Shared.ParameterField' cannot be
converted
to '1 dimensional array of Crystal.Decisions.Shared.ParameterField'

Same for
paramField = CreateParamater("Periode")
Return paramDiscreteValue

Any idea what causes this?

Alison
"AMDRIT" <am****@hotmail.com> wrote in message
news:ur*************@TK2MSFTNGP14.phx.gbl...
Wow, you do all that for Crystal Reports? What is
RapportAIRCOStoringen?
Here is all I do for CR

Dim x As CrystalDecisions.CrystalReports.Engine.ReportDocum ent

x.Load(sReportPath) 'Reports are not embedded resources
x.SetParameterValue("Paramater1", Paramaters(1)) 'Dynamic
Paramaters
x.SetParameterValue("Paramater2", Paramaters(2))
x.SetDataSource(mydata) 'Strongly Typed Datasets

Me.CrystalReportViewer1.ReportSource = x
Me.CrystalReportViewer1.PrintReport()
'Now to answer your question about your code, hmm

Ok, first

Never --> Dim x as new object
'This is silly, lazy and unprofessional. So if you are in high
school, keep the course.
Instead --> Dim x as object
Set x = new object
'Reserve your space and contract
'Then make use of it.

I think this is your problem

myReport.SetParameterValue("FiliaalKeuze", discreteVal)

Why are you setting the crView paramaters and the myReport paramaters?
-->crViewer.ParameterFieldInfo = paramFields
-->myReport.SetParameterValue("Periode", rangeVal)

I think that myReport is the only think that needs to be set
I had to spent time reading your code to understand what you were doing.

Here is an attempt to clean it up.

Private Sub TestIT()

Dim myReport As RapportAIRCOStoringen
Dim paramFields As ParameterFields
Dim paramField As ParameterField

Dim BeginPeriode As String
Dim EindPeriode As String

'Todo wrap everything in try
paramFields = New ParameterFields

Try
BeginPeriode = Request.QueryString("BeginPeriode")
EindPeriode = Request.QueryString("EindPeriode")
Catch ex As Exception
Dim exCustom As ApplicationException
exCustom = New ApplicationException("Unable to parse Query
Paramaters.", ex)
Throw exCustom
End Try

'Todo wrap in try
paramField = CreateParamater("FiliaalKeuze")
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2044))
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2344))
myReport.SetParameterValue("FiliaalKeuze", paramField)
'paramFields.Add(paramField) --> Not needed

'Todo wrap in try
paramField = CreateParamater("Periode")
paramField.CurrentValues.Add(CreateParameterRangeV alue(BeginPeriode,
EindPeriode))
myReport.SetParameterValue("Periode", paramField)
'paramFields.Add(paramField)--> Not needed

'Todo wrap in try, i don't think you need this
'myReport.SetParameterValue("Periode", rangeVal)
'myReport.SetParameterValue("FiliaalKeuze", discreteVal)

'Todo, determine if we need this step; I don't think you do
'crViewer.ParameterFieldInfo = paramFields

crViewer.ReportSource = myReport

End Sub

Private Function CreateParamater(ByVal ParamaterName As String) As
ParameterField
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParamaterName

Return paramField

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As Object,
ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function

"Alison Givens" <in**@cross-it.nl> wrote in message
news:eW*************@TK2MSFTNGP11.phx.gbl...
...... that nobody knows the answer.
I can't imagine that I am the only one that uses parameters in CR.

So, my question again:

I have the following problem.
(VB.NET 2003 with CR)

I have a report with a multiple-value discrete value and a rangevalue.
The report shows fine in the viewer, but when I hit the export to pdf
button, it only uses one of two discrete values.

This is the code:
Dim BeginPeriode As String
Dim EindPeriode As String

BeginPeriode = Request.QueryString("BeginPeriode")
EindPeriode = Request.QueryString("EindPeriode")

Dim myReport As New RapportAIRCOStoringen

Dim paramFields As New ParameterFields
Dim paramField As New ParameterField
Dim discreteVal As New ParameterDiscreteValue
Dim rangeVal As New ParameterRangeValue

paramField.ParameterFieldName = "FiliaalKeuze"
discreteVal.Value = "2044"
paramField.CurrentValues.Add(discreteVal)

discreteVal = New ParameterDiscreteValue
discreteVal.Value = "2344"
paramField.CurrentValues.Add(discreteVal)

paramFields.Add(paramField)

paramField = New ParameterField

paramField.ParameterFieldName = "Periode"

rangeVal.StartValue = BeginPeriode
rangeVal.EndValue = EindPeriode
paramField.CurrentValues.Add(rangeVal)

paramFields.Add(paramField)

crViewer.ParameterFieldInfo = paramFields
myReport.SetParameterValue("Periode", rangeVal)
myReport.SetParameterValue("FiliaalKeuze", discreteVal)
crViewer.ReportSource = myReport

As you can see I use myReport.SetParameterValue to feed the pdf.
It goes wrong with the discrete value. It only sees the second value I
entered and not the first.
How can I get this going?
Kind regards,
Alison




Feb 20 '06 #5
Ok, first the isue you were having with the "Blue lines" is:

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue()
--> Retun type is expecting an array of ParameterDiscreteValue

it should be

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue
--> Retun type is expecting an single ParameterDiscreteValue

Second (Mostly because I was bored and also because I am still a novice), I
have altered your code yet again.
Private Enum FileNameFormats
SessionID = 0
GUIDDashes = 1
GUIDNoDashes = 2
End Enum

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()

Dim myReport As RapportAIRCOStoringen
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions

Try

Try
PrepareReport(myReport)
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to prepare report.", ex)
Throw exc
End Try

Try
'exporteren to pdf
myExportOptions = GetExportOptions(FileNameFormats.GUIDNoDashes,
CType(myReport,
CrystalDecisions.CrystalReports.Engine.ReportDocum ent).ExportOptions)
myReport.Export()

Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to export report.", ex)
Throw exc
End Try

crViewer.ReportSource = myReport

Session("exportbestand") = CType(myExportOptions.DestinationOptions,
CrystalDecisions.Shared.DiskFileDestinationOptions ).DiskFileName

Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try

End Sub

#Region "Page Implementation"

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload
Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

System.IO.File.Delete(myExportFile)
End Sub

#End Region

#Region "Report Setup"

Private Sub PrepareReport(ByVal myReport As
CrystalDecisions.CrystalReports.Engine.ReportDocum ent)

Dim paramFields As ParameterFields
Dim paramField As ParameterField

Const SessionExecption As String = "Unable to read session objects."

Try

paramFields = New ParameterFields
Try
paramField = CreateParameter("FiliaalKeuze")
paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("DiscreteValue1")))
paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("DiscreteValue1")))
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption, ex)
Throw exc
End Try

myReport.SetParameterValue("FiliaalKeuze", paramField)

Try
'Todo wrap in try
paramField = CreateParameter("Periode")
paramField.CurrentValues.Add(CreateParameterRangeV alue(GetSessionValue("BeginPeriode"),
GetSessionValue("EindPeriode")))
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption, ex)
Throw exc
End Try

myReport.SetParameterValue("Periode", paramField)

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to set paramater
value.", ex)
Throw exc

End Try
End Sub

Private Function CreateParameter(ByVal ParameterName As String) As
ParameterField
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParameterName

Return paramField

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue()

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

'Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As Object,
ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function

#End Region

#Region "Report Export"

Private Function GetExportOptions(ByVal UniqueFormat As FileNameFormats,
ByVal ExportOptions As CrystalDecisions.Shared.ExportOptions) As
CrystalDecisions.Shared.ExportOptions

Dim myExportFile As String
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
Dim myDiskFileDestinationOptions As
CrystalDecisions.Shared.DiskFileDestinationOptions

Try

Select Case UniqueFormat
Case FileNameFormats.SessionID
myExportFile = Session.SessionID.ToString
Case FileNameFormats.GUIDDashes
myExportFile = System.Guid.NewGuid.ToString("D")
Case FileNameFormats.GUIDNoDashes
myExportFile = System.Guid.NewGuid.ToString("N")
End Select

myExportFile = System.IO.Path.Combine(GetExportRoot,
String.Format("PDF_{0}.pdf", myExportFile))

myDiskFileDestinationOptions = New
CrystalDecisions.Shared.DiskFileDestinationOptions
myDiskFileDestinationOptions.DiskFileName = myExportFile

myExportOptions = ExportOptions

With myExportOptions
.DestinationOptions = myDiskFileDestinationOptions
.ExportDestinationType = .ExportDestinationType.DiskFile
.ExportFormatType = .ExportFormatType.PortableDocFormat
End With

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to prepare export
options.", ex)
Throw exc

End Try

Return myExportOptions

End Function

Private Function GetExportRoot(ByVal FromApplication As Boolean) As String

Dim strExportRoot As String

If FromApplication Then
Try
Application.lock()
strExportRoot = Application("ReportExportRoot")
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to lock Web Application for
read.", ex)
Throw exc
Finally
Application.unlock()
End Try
Else
strExportRoot = Session("ReportExportRoot")
End If

Return strExportRoot

End Function

#End Region

#Region "Navigation Implementation"

Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"

Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

Response.WriteFile(myExportFile)
Response.Flush()
Response.Close()

System.IO.File.Delete(myExportFile)

End Sub

Private Sub cmdEerste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEerste.Click
crViewer.ShowFirstPage()
End Sub

Private Sub cmdLaatste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdLaatste.Click
crViewer.ShowLastPage()
End Sub

Private Sub cmdTerug_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdTerug.Click
crViewer.ShowPreviousPage()
End Sub

Private Sub cmdVerder_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdVerder.Click
crViewer.ShowNextPage()
End Sub

Private Sub drpZoom_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles drpZoom.SelectedIndexChanged
crViewer.Zoom(drpZoom.SelectedItem.Value)
End Sub

#End Region
"Alison Givens" <in**@cross-it.nl> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
Perhaps you could share your resulting code for comparison? Did you see
that I suggested the error in your code was

myReport.SetParameterValue("FiliaalKeuze", discreteVal) 'You only call
this statement once (Effectively 2344) but you wanted two values.


To get the thing going, it would be enough for me at first to know how to
call the statement twice, so the other value is forwarded too.
(btw, these two values will be SessionObjects two, but I did it hardcoded
for testing)
Best would be ofcourse that I learn to do it 'clean' of course. I am a
real newbee at this.

Here is the rest of my code:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.CrystalReports.Engine.ReportDocum ent
Imports CrystalDecisions.Shared
Imports System.IO
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()

Dim myReport As RapportAIRCOStoringen
Dim paramFields As ParameterFields
Dim paramField As ParameterField

Dim BeginPeriode As String
Dim EindPeriode As String

'Todo wrap everything in try
paramFields = New ParameterFields

Try
BeginPeriode = Request.QueryString("BeginPeriode")
EindPeriode = Request.QueryString("EindPeriode")
Catch ex As Exception
Dim exCustom As ApplicationException
exCustom = New ApplicationException("Unable to parse Query
Paramaters.", ex)
Throw exCustom
End Try

'Todo wrap in try
paramField = CreateParameter("FiliaalKeuze")
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2044))
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2344))
myReport.SetParameterValue("FiliaalKeuze", paramField)
'Todo wrap in try
paramField = CreateParameter("Periode")

paramField.CurrentValues.Add(CreateParameterRangeV alue(BeginPeriode,
EindPeriode))
myReport.SetParameterValue("Periode", paramField)
crViewer.ReportSource = myReport
'exporteren to pdf
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
Dim myDiskFileDestinationOptions As
CrystalDecisions.Shared.DiskFileDestinationOptions
Dim myExportFile As String

myExportFile = "\\192.168.2.106\syn2sql$\PDF_" &
Session.SessionID.ToString & ".pdf"
myDiskFileDestinationOptions = New
CrystalDecisions.Shared.DiskFileDestinationOptions
myDiskFileDestinationOptions.DiskFileName = myExportFile
myExportOptions = myReport.ExportOptions
With myExportOptions
.DestinationOptions = myDiskFileDestinationOptions
.ExportDestinationType = .ExportDestinationType.DiskFile
.ExportFormatType = .ExportFormatType.PortableDocFormat
End With

Try
myReport.Export()
Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try

Session("exportbestand") = myExportFile
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

Response.WriteFile(myExportFile)
Response.Flush()
Response.Close()

System.IO.File.Delete(myExportFile)
End Sub

Private Function CreateParameter(ByVal ParameterName As String) As
ParameterField()
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParameterName

'Return paramField

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue()

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

'Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As Object,
ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function
Private Sub cmdEerste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEerste.Click
crViewer.ShowFirstPage()
End Sub

Private Sub cmdLaatste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdLaatste.Click
crViewer.ShowLastPage()
End Sub

Private Sub cmdTerug_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdTerug.Click
crViewer.ShowPreviousPage()
End Sub

Private Sub cmdVerder_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdVerder.Click
crViewer.ShowNextPage()
End Sub

Private Sub drpZoom_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles drpZoom.SelectedIndexChanged
crViewer.Zoom(drpZoom.SelectedItem.Value)
End Sub
Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload
Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

System.IO.File.Delete(myExportFile)
End Sub
End Class


"Alison Givens" <in**@cross-it.nl> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
When I use your solution I get blue lines under the text like this

paramField = CreateParamater("FiliaalKeuze")
The text is:
Value of type '1 dimensional array of
CrystalDecisions.Shared.ParameterField' cannot be converted
to 'Crystal.Decisions.Shared.ParameterField'

Return paramField
The text is:
Value of type 'CrystalDecisions.Shared.ParameterField' cannot be
converted
to '1 dimensional array of Crystal.Decisions.Shared.ParameterField'

Same for
paramField = CreateParamater("Periode")
Return paramDiscreteValue

Any idea what causes this?

Alison
"AMDRIT" <am****@hotmail.com> wrote in message
news:ur*************@TK2MSFTNGP14.phx.gbl...
Wow, you do all that for Crystal Reports? What is
RapportAIRCOStoringen?
Here is all I do for CR

Dim x As CrystalDecisions.CrystalReports.Engine.ReportDocum ent

x.Load(sReportPath) 'Reports are not embedded resources
x.SetParameterValue("Paramater1", Paramaters(1)) 'Dynamic
Paramaters
x.SetParameterValue("Paramater2", Paramaters(2))
x.SetDataSource(mydata) 'Strongly Typed Datasets

Me.CrystalReportViewer1.ReportSource = x
Me.CrystalReportViewer1.PrintReport()
'Now to answer your question about your code, hmm

Ok, first

Never --> Dim x as new object
'This is silly, lazy and unprofessional. So if you are in high
school, keep the course.
Instead --> Dim x as object
Set x = new object
'Reserve your space and contract
'Then make use of it.

I think this is your problem

myReport.SetParameterValue("FiliaalKeuze", discreteVal)

Why are you setting the crView paramaters and the myReport paramaters?
-->crViewer.ParameterFieldInfo = paramFields
-->myReport.SetParameterValue("Periode", rangeVal)

I think that myReport is the only think that needs to be set
I had to spent time reading your code to understand what you were
doing.

Here is an attempt to clean it up.

Private Sub TestIT()

Dim myReport As RapportAIRCOStoringen
Dim paramFields As ParameterFields
Dim paramField As ParameterField

Dim BeginPeriode As String
Dim EindPeriode As String

'Todo wrap everything in try
paramFields = New ParameterFields

Try
BeginPeriode = Request.QueryString("BeginPeriode")
EindPeriode = Request.QueryString("EindPeriode")
Catch ex As Exception
Dim exCustom As ApplicationException
exCustom = New ApplicationException("Unable to parse Query
Paramaters.", ex)
Throw exCustom
End Try

'Todo wrap in try
paramField = CreateParamater("FiliaalKeuze")
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2044))
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2344))
myReport.SetParameterValue("FiliaalKeuze", paramField)
'paramFields.Add(paramField) --> Not needed

'Todo wrap in try
paramField = CreateParamater("Periode")
paramField.CurrentValues.Add(CreateParameterRangeV alue(BeginPeriode,
EindPeriode))
myReport.SetParameterValue("Periode", paramField)
'paramFields.Add(paramField)--> Not needed

'Todo wrap in try, i don't think you need this
'myReport.SetParameterValue("Periode", rangeVal)
'myReport.SetParameterValue("FiliaalKeuze", discreteVal)

'Todo, determine if we need this step; I don't think you do
'crViewer.ParameterFieldInfo = paramFields

crViewer.ReportSource = myReport

End Sub

Private Function CreateParamater(ByVal ParamaterName As String) As
ParameterField
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParamaterName

Return paramField

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object)
As ParameterDiscreteValue

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As Object,
ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function

"Alison Givens" <in**@cross-it.nl> wrote in message
news:eW*************@TK2MSFTNGP11.phx.gbl...
> ...... that nobody knows the answer.
> I can't imagine that I am the only one that uses parameters in CR.
>
> So, my question again:
>
> I have the following problem.
> (VB.NET 2003 with CR)
>
> I have a report with a multiple-value discrete value and a rangevalue.
> The report shows fine in the viewer, but when I hit the export to pdf
> button, it only uses one of two discrete values.
>
> This is the code:
> Dim BeginPeriode As String
> Dim EindPeriode As String
>
> BeginPeriode = Request.QueryString("BeginPeriode")
> EindPeriode = Request.QueryString("EindPeriode")
>
> Dim myReport As New RapportAIRCOStoringen
>
> Dim paramFields As New ParameterFields
> Dim paramField As New ParameterField
> Dim discreteVal As New ParameterDiscreteValue
> Dim rangeVal As New ParameterRangeValue
>
> paramField.ParameterFieldName = "FiliaalKeuze"
> discreteVal.Value = "2044"
> paramField.CurrentValues.Add(discreteVal)
>
> discreteVal = New ParameterDiscreteValue
> discreteVal.Value = "2344"
> paramField.CurrentValues.Add(discreteVal)
>
> paramFields.Add(paramField)
>
> paramField = New ParameterField
>
> paramField.ParameterFieldName = "Periode"
>
> rangeVal.StartValue = BeginPeriode
> rangeVal.EndValue = EindPeriode
> paramField.CurrentValues.Add(rangeVal)
>
> paramFields.Add(paramField)
>
> crViewer.ParameterFieldInfo = paramFields
> myReport.SetParameterValue("Periode", rangeVal)
> myReport.SetParameterValue("FiliaalKeuze", discreteVal)
> crViewer.ReportSource = myReport
>
> As you can see I use myReport.SetParameterValue to feed the pdf.
> It goes wrong with the discrete value. It only sees the second value I
> entered and not the first.
> How can I get this going?
>
>
> Kind regards,
> Alison
>
>
>
>



Feb 20 '06 #6
I used the code as you suggested, but again I get blue underlines.
First with every GetSessionValue,it has a blue underline:
Name GetSessionValue is not declared

and the other blue underline is GetExportRoot
myExportFile = System.IO.Path.Combine(GetExportRoot,
String.Format("PDF_{0}.pdf", myExportFile))
Says:Argument not specified for parameter 'FromApplication' of
'Private Function GetExportRoot(FromApplication As Boolean) As String'.

I pasted the code again for your convenience.

Private Enum FileNameFormats
SessionID = 0
GUIDDashes = 1
GUIDNoDashes = 2
End Enum
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
Dim myReport As RapportAIRCOStoringen
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions

Try

Try
PrepareReport(myReport)
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to prepare report.",
ex)
Throw exc
End Try

Try
'exporteren to pdf
myExportOptions =
GetExportOptions(FileNameFormats.GUIDNoDashes, CType(myReport,
CrystalDecisions.CrystalReports.Engine.ReportDocum ent).ExportOptions)
myReport.Export()

Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to export report.",
ex)
Throw exc
End Try

crViewer.ReportSource = myReport

Session("exportbestand") =
CType(myExportOptions.DestinationOptions,
CrystalDecisions.Shared.DiskFileDestinationOptions ).DiskFileName

Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try


End Sub

#End Region

#Region "Page Implementation"

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload
Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

System.IO.File.Delete(myExportFile)
End Sub

#End Region

#Region "Report Setup"

Private Sub PrepareReport(ByVal myReport As
CrystalDecisions.CrystalReports.Engine.ReportDocum ent)

Dim paramFields As ParameterFields
Dim paramField As ParameterField

Const SessionExecption As String = "Unable to read session objects."

Try

paramFields = New ParameterFields
Try
paramField = CreateParameter("FiliaalKeuze")
paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("DiscreteValue1")))
paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("DiscreteValue1")))

Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption, ex)
Throw exc
End Try

myReport.SetParameterValue("FiliaalKeuze", paramField)

Try
'Todo wrap in try
paramField = CreateParameter("Periode")
paramField.CurrentValues.Add(CreateParameterRangeV alue(GetSessionValue("BeginPeriode"),
GetSessionValue("EindPeriode")))
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption, ex)
Throw exc
End Try

myReport.SetParameterValue("Periode", paramField)

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to set
paramatervalue.", ex)
Throw exc

End Try
End Sub

Private Function CreateParameter(ByVal ParameterName As String) As
ParameterField
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParameterName

Return paramField

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As Object,
ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function

#End Region

#Region "Report Export"

Private Function GetExportOptions(ByVal UniqueFormat As FileNameFormats,
ByVal ExportOptions As CrystalDecisions.Shared.ExportOptions) As
CrystalDecisions.Shared.ExportOptions

Dim myExportFile As String
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
Dim myDiskFileDestinationOptions As
CrystalDecisions.Shared.DiskFileDestinationOptions

Try

Select Case UniqueFormat
Case FileNameFormats.SessionID
myExportFile = Session.SessionID.ToString
Case FileNameFormats.GUIDDashes
myExportFile = System.Guid.NewGuid.ToString("D")
Case FileNameFormats.GUIDNoDashes
myExportFile = System.Guid.NewGuid.ToString("N")
End Select

myExportFile = System.IO.Path.Combine(GetExportRoot,
String.Format("PDF_{0}.pdf", myExportFile))

myDiskFileDestinationOptions = New
CrystalDecisions.Shared.DiskFileDestinationOptions
myDiskFileDestinationOptions.DiskFileName = myExportFile

myExportOptions = ExportOptions

With myExportOptions
.DestinationOptions = myDiskFileDestinationOptions
.ExportDestinationType = .ExportDestinationType.DiskFile
.ExportFormatType = .ExportFormatType.PortableDocFormat
End With

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to prepare export
options.", ex)
Throw exc

End Try

Return myExportOptions

End Function

Private Function GetExportRoot(ByVal FromApplication As Boolean) As
String

Dim strExportRoot As String

If FromApplication Then
Try
Application.Lock()
strExportRoot = Application("ReportExportRoot")
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to lock Web
Application for read.", ex)
Throw exc
Finally
Application.UnLock()
End Try
Else
strExportRoot = Session("ReportExportRoot")
End If

Return strExportRoot

End Function

#End Region

#Region "Navigation Implementation"

Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"

Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

Response.WriteFile(myExportFile)
Response.Flush()
Response.Close()

System.IO.File.Delete(myExportFile)

End Sub

Private Sub cmdEerste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEerste.Click
crViewer.ShowFirstPage()
End Sub

Private Sub cmdLaatste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdLaatste.Click
crViewer.ShowLastPage()
End Sub

Private Sub cmdTerug_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdTerug.Click
crViewer.ShowPreviousPage()
End Sub

Private Sub cmdVerder_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdVerder.Click
crViewer.ShowNextPage()
End Sub

Private Sub drpZoom_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles drpZoom.SelectedIndexChanged
crViewer.Zoom(drpZoom.SelectedItem.Value)
End Sub

#End Region
End Class


"AMDRIT" <am****@hotmail.com> wrote in message
news:Op**************@TK2MSFTNGP09.phx.gbl...
Ok, first the isue you were having with the "Blue lines" is:

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue()
--> Retun type is expecting an array of ParameterDiscreteValue

it should be

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue
--> Retun type is expecting an single ParameterDiscreteValue

Second (Mostly because I was bored and also because I am still a novice),
I have altered your code yet again.
Private Enum FileNameFormats
SessionID = 0
GUIDDashes = 1
GUIDNoDashes = 2
End Enum

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()

Dim myReport As RapportAIRCOStoringen
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions

Try

Try
PrepareReport(myReport)
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to prepare report.", ex)
Throw exc
End Try

Try
'exporteren to pdf
myExportOptions = GetExportOptions(FileNameFormats.GUIDNoDashes,
CType(myReport,
CrystalDecisions.CrystalReports.Engine.ReportDocum ent).ExportOptions)
myReport.Export()

Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to export report.", ex)
Throw exc
End Try

crViewer.ReportSource = myReport

Session("exportbestand") = CType(myExportOptions.DestinationOptions,
CrystalDecisions.Shared.DiskFileDestinationOptions ).DiskFileName

Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try

End Sub

#Region "Page Implementation"

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload
Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

System.IO.File.Delete(myExportFile)
End Sub

#End Region

#Region "Report Setup"

Private Sub PrepareReport(ByVal myReport As
CrystalDecisions.CrystalReports.Engine.ReportDocum ent)

Dim paramFields As ParameterFields
Dim paramField As ParameterField

Const SessionExecption As String = "Unable to read session objects."

Try

paramFields = New ParameterFields
Try
paramField = CreateParameter("FiliaalKeuze")

paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("DiscreteValue1")))

paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("DiscreteValue1")))
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption, ex)
Throw exc
End Try

myReport.SetParameterValue("FiliaalKeuze", paramField)

Try
'Todo wrap in try
paramField = CreateParameter("Periode")

paramField.CurrentValues.Add(CreateParameterRangeV alue(GetSessionValue("BeginPeriode"),
GetSessionValue("EindPeriode")))
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption, ex)
Throw exc
End Try

myReport.SetParameterValue("Periode", paramField)

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to set paramater
value.", ex)
Throw exc

End Try
End Sub

Private Function CreateParameter(ByVal ParameterName As String) As
ParameterField
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParameterName

Return paramField

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue()

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

'Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As Object,
ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function

#End Region

#Region "Report Export"

Private Function GetExportOptions(ByVal UniqueFormat As FileNameFormats,
ByVal ExportOptions As CrystalDecisions.Shared.ExportOptions) As
CrystalDecisions.Shared.ExportOptions

Dim myExportFile As String
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
Dim myDiskFileDestinationOptions As
CrystalDecisions.Shared.DiskFileDestinationOptions

Try

Select Case UniqueFormat
Case FileNameFormats.SessionID
myExportFile = Session.SessionID.ToString
Case FileNameFormats.GUIDDashes
myExportFile = System.Guid.NewGuid.ToString("D")
Case FileNameFormats.GUIDNoDashes
myExportFile = System.Guid.NewGuid.ToString("N")
End Select

myExportFile = System.IO.Path.Combine(GetExportRoot,
String.Format("PDF_{0}.pdf", myExportFile))

myDiskFileDestinationOptions = New
CrystalDecisions.Shared.DiskFileDestinationOptions
myDiskFileDestinationOptions.DiskFileName = myExportFile

myExportOptions = ExportOptions

With myExportOptions
.DestinationOptions = myDiskFileDestinationOptions
.ExportDestinationType = .ExportDestinationType.DiskFile
.ExportFormatType = .ExportFormatType.PortableDocFormat
End With

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to prepare export
options.", ex)
Throw exc

End Try

Return myExportOptions

End Function

Private Function GetExportRoot(ByVal FromApplication As Boolean) As
String

Dim strExportRoot As String

If FromApplication Then
Try
Application.lock()
strExportRoot = Application("ReportExportRoot")
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to lock Web Application for
read.", ex)
Throw exc
Finally
Application.unlock()
End Try
Else
strExportRoot = Session("ReportExportRoot")
End If

Return strExportRoot

End Function

#End Region

#Region "Navigation Implementation"

Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"

Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

Response.WriteFile(myExportFile)
Response.Flush()
Response.Close()

System.IO.File.Delete(myExportFile)

End Sub

Private Sub cmdEerste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEerste.Click
crViewer.ShowFirstPage()
End Sub

Private Sub cmdLaatste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdLaatste.Click
crViewer.ShowLastPage()
End Sub

Private Sub cmdTerug_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdTerug.Click
crViewer.ShowPreviousPage()
End Sub

Private Sub cmdVerder_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdVerder.Click
crViewer.ShowNextPage()
End Sub

Private Sub drpZoom_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles drpZoom.SelectedIndexChanged
crViewer.Zoom(drpZoom.SelectedItem.Value)
End Sub

#End Region
"Alison Givens" <in**@cross-it.nl> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
Perhaps you could share your resulting code for comparison? Did you see
that I suggested the error in your code was

myReport.SetParameterValue("FiliaalKeuze", discreteVal) 'You only call
this statement once (Effectively 2344) but you wanted two values.


To get the thing going, it would be enough for me at first to know how to
call the statement twice, so the other value is forwarded too.
(btw, these two values will be SessionObjects two, but I did it hardcoded
for testing)
Best would be ofcourse that I learn to do it 'clean' of course. I am a
real newbee at this.

Here is the rest of my code:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.CrystalReports.Engine.ReportDocum ent
Imports CrystalDecisions.Shared
Imports System.IO
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()

Dim myReport As RapportAIRCOStoringen
Dim paramFields As ParameterFields
Dim paramField As ParameterField

Dim BeginPeriode As String
Dim EindPeriode As String

'Todo wrap everything in try
paramFields = New ParameterFields

Try
BeginPeriode = Request.QueryString("BeginPeriode")
EindPeriode = Request.QueryString("EindPeriode")
Catch ex As Exception
Dim exCustom As ApplicationException
exCustom = New ApplicationException("Unable to parse Query
Paramaters.", ex)
Throw exCustom
End Try

'Todo wrap in try
paramField = CreateParameter("FiliaalKeuze")
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2044))
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2344))
myReport.SetParameterValue("FiliaalKeuze", paramField)
'Todo wrap in try
paramField = CreateParameter("Periode")

paramField.CurrentValues.Add(CreateParameterRangeV alue(BeginPeriode,
EindPeriode))
myReport.SetParameterValue("Periode", paramField)
crViewer.ReportSource = myReport
'exporteren to pdf
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
Dim myDiskFileDestinationOptions As
CrystalDecisions.Shared.DiskFileDestinationOptions
Dim myExportFile As String

myExportFile = "\\192.168.2.106\syn2sql$\PDF_" &
Session.SessionID.ToString & ".pdf"
myDiskFileDestinationOptions = New
CrystalDecisions.Shared.DiskFileDestinationOptions
myDiskFileDestinationOptions.DiskFileName = myExportFile
myExportOptions = myReport.ExportOptions
With myExportOptions
.DestinationOptions = myDiskFileDestinationOptions
.ExportDestinationType = .ExportDestinationType.DiskFile
.ExportFormatType = .ExportFormatType.PortableDocFormat
End With

Try
myReport.Export()
Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try

Session("exportbestand") = myExportFile
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

Response.WriteFile(myExportFile)
Response.Flush()
Response.Close()

System.IO.File.Delete(myExportFile)
End Sub

Private Function CreateParameter(ByVal ParameterName As String) As
ParameterField()
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParameterName

'Return paramField

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object)
As ParameterDiscreteValue()

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

'Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As Object,
ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function
Private Sub cmdEerste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEerste.Click
crViewer.ShowFirstPage()
End Sub

Private Sub cmdLaatste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdLaatste.Click
crViewer.ShowLastPage()
End Sub

Private Sub cmdTerug_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdTerug.Click
crViewer.ShowPreviousPage()
End Sub

Private Sub cmdVerder_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdVerder.Click
crViewer.ShowNextPage()
End Sub

Private Sub drpZoom_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles drpZoom.SelectedIndexChanged
crViewer.Zoom(drpZoom.SelectedItem.Value)
End Sub
Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload
Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

System.IO.File.Delete(myExportFile)
End Sub
End Class


"Alison Givens" <in**@cross-it.nl> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
When I use your solution I get blue lines under the text like this

paramField = CreateParamater("FiliaalKeuze")
The text is:
Value of type '1 dimensional array of
CrystalDecisions.Shared.ParameterField' cannot be converted
to 'Crystal.Decisions.Shared.ParameterField'

Return paramField
The text is:
Value of type 'CrystalDecisions.Shared.ParameterField' cannot be
converted
to '1 dimensional array of Crystal.Decisions.Shared.ParameterField'

Same for
paramField = CreateParamater("Periode")
Return paramDiscreteValue

Any idea what causes this?

Alison
"AMDRIT" <am****@hotmail.com> wrote in message
news:ur*************@TK2MSFTNGP14.phx.gbl...
> Wow, you do all that for Crystal Reports? What is
> RapportAIRCOStoringen?
>
>
> Here is all I do for CR
>
> Dim x As CrystalDecisions.CrystalReports.Engine.ReportDocum ent
>
> x.Load(sReportPath) 'Reports are not embedded resources
> x.SetParameterValue("Paramater1", Paramaters(1)) 'Dynamic
> Paramaters
> x.SetParameterValue("Paramater2", Paramaters(2))
> x.SetDataSource(mydata) 'Strongly Typed Datasets
>
> Me.CrystalReportViewer1.ReportSource = x
> Me.CrystalReportViewer1.PrintReport()
>
>
> 'Now to answer your question about your code, hmm
>
> Ok, first
>
> Never --> Dim x as new object
> 'This is silly, lazy and unprofessional. So if you are in high
> school, keep the course.
>
>
> Instead --> Dim x as object
> Set x = new object
> 'Reserve your space and contract
> 'Then make use of it.
>
> I think this is your problem
>
> myReport.SetParameterValue("FiliaalKeuze", discreteVal)
>
> Why are you setting the crView paramaters and the myReport paramaters?
> -->crViewer.ParameterFieldInfo = paramFields
> -->myReport.SetParameterValue("Periode", rangeVal)
>
> I think that myReport is the only think that needs to be set
>
>
> I had to spent time reading your code to understand what you were
> doing.
>
> Here is an attempt to clean it up.
>
> Private Sub TestIT()
>
> Dim myReport As RapportAIRCOStoringen
> Dim paramFields As ParameterFields
> Dim paramField As ParameterField
>
> Dim BeginPeriode As String
> Dim EindPeriode As String
>
> 'Todo wrap everything in try
> paramFields = New ParameterFields
>
> Try
> BeginPeriode = Request.QueryString("BeginPeriode")
> EindPeriode = Request.QueryString("EindPeriode")
> Catch ex As Exception
> Dim exCustom As ApplicationException
> exCustom = New ApplicationException("Unable to parse Query
> Paramaters.", ex)
> Throw exCustom
> End Try
>
> 'Todo wrap in try
> paramField = CreateParamater("FiliaalKeuze")
> paramField.CurrentValues.Add(CreateParameterDiscre teValue(2044))
> paramField.CurrentValues.Add(CreateParameterDiscre teValue(2344))
> myReport.SetParameterValue("FiliaalKeuze", paramField)
> 'paramFields.Add(paramField) --> Not needed
>
> 'Todo wrap in try
> paramField = CreateParamater("Periode")
>
> paramField.CurrentValues.Add(CreateParameterRangeV alue(BeginPeriode,
> EindPeriode))
> myReport.SetParameterValue("Periode", paramField)
> 'paramFields.Add(paramField)--> Not needed
>
> 'Todo wrap in try, i don't think you need this
> 'myReport.SetParameterValue("Periode", rangeVal)
> 'myReport.SetParameterValue("FiliaalKeuze", discreteVal)
>
> 'Todo, determine if we need this step; I don't think you do
> 'crViewer.ParameterFieldInfo = paramFields
>
> crViewer.ReportSource = myReport
>
> End Sub
>
> Private Function CreateParamater(ByVal ParamaterName As String) As
> ParameterField
> Dim paramField As ParameterField
>
> paramField = New ParameterField
> paramField.ParameterFieldName = ParamaterName
>
> Return paramField
>
> End Function
>
> Private Function CreateParameterDiscreteValue(ByVal Value As Object)
> As ParameterDiscreteValue
>
> Dim paramDiscreteValue As ParameterDiscreteValue
> paramDiscreteValue = New ParameterDiscreteValue
> paramDiscreteValue = Value
>
> Return paramDiscreteValue
>
> End Function
>
> Private Function CreateParameterRangeValue(ByVal StartRange As
> Object, ByVal EndRange As Object) As ParameterRangeValue
> Dim paramRangeValue As ParameterRangeValue
>
> paramRangeValue = New ParameterRangeValue
>
> paramRangeValue.StartValue = StartRange
> paramRangeValue.EndValue = EndRange
>
> Return paramRangeValue
> End Function
>
> "Alison Givens" <in**@cross-it.nl> wrote in message
> news:eW*************@TK2MSFTNGP11.phx.gbl...
>> ...... that nobody knows the answer.
>> I can't imagine that I am the only one that uses parameters in CR.
>>
>> So, my question again:
>>
>> I have the following problem.
>> (VB.NET 2003 with CR)
>>
>> I have a report with a multiple-value discrete value and a
>> rangevalue.
>> The report shows fine in the viewer, but when I hit the export to pdf
>> button, it only uses one of two discrete values.
>>
>> This is the code:
>> Dim BeginPeriode As String
>> Dim EindPeriode As String
>>
>> BeginPeriode = Request.QueryString("BeginPeriode")
>> EindPeriode = Request.QueryString("EindPeriode")
>>
>> Dim myReport As New RapportAIRCOStoringen
>>
>> Dim paramFields As New ParameterFields
>> Dim paramField As New ParameterField
>> Dim discreteVal As New ParameterDiscreteValue
>> Dim rangeVal As New ParameterRangeValue
>>
>> paramField.ParameterFieldName = "FiliaalKeuze"
>> discreteVal.Value = "2044"
>> paramField.CurrentValues.Add(discreteVal)
>>
>> discreteVal = New ParameterDiscreteValue
>> discreteVal.Value = "2344"
>> paramField.CurrentValues.Add(discreteVal)
>>
>> paramFields.Add(paramField)
>>
>> paramField = New ParameterField
>>
>> paramField.ParameterFieldName = "Periode"
>>
>> rangeVal.StartValue = BeginPeriode
>> rangeVal.EndValue = EindPeriode
>> paramField.CurrentValues.Add(rangeVal)
>>
>> paramFields.Add(paramField)
>>
>> crViewer.ParameterFieldInfo = paramFields
>> myReport.SetParameterValue("Periode", rangeVal)
>> myReport.SetParameterValue("FiliaalKeuze", discreteVal)
>> crViewer.ReportSource = myReport
>>
>> As you can see I use myReport.SetParameterValue to feed the pdf.
>> It goes wrong with the discrete value. It only sees the second value
>> I
>> entered and not the first.
>> How can I get this going?
>>
>>
>> Kind regards,
>> Alison
>>
>>
>>
>>
>
>



Feb 21 '06 #7
Good morning,

I just realized you keep different hours than me. Please keep in mind that
all the code that I have submitted to you is wholly untested and therefore
the jist of what I was conveying should be taken into context. I attempt to
answer your direct question before going off onto a tangent.

1. You need a function named GetSessionValue
The signature would look like: GetSessionValue(KeyName as string) as
object and all it would do is return Session.Item(KeyName)

2. Correct the line
myExportFile = System.IO.Path.Combine(GetExportRoot,
String.Format("PDF_{0}.pdf", myExportFile))
to
myExportFile = System.IO.Path.Combine(GetExportRoot(false),
String.Format("PDF_{0}.pdf", myExportFile))
or
myExportFile = System.IO.Path.Combine(GetExportRoot(true),
String.Format("PDF_{0}.pdf", myExportFile))

If you are to use the function GetExportRoot, then you must set up your
global.asax to set a global variable to hold ReportExportRoot in
Application_OnStart, and if you want each session to get a copy of that
value in the global.asax Session_OnStart, have it read the Application
variable.

The goal here is to store environmental setting information out of compiled
code. It's more work to set it up, but will not require you to compile the
application everytime you want to make a change.

ideal uses for the web config (DbConnection, ServerLocations, FileShares,
WebService URLs)

keep in mind though, each time you modify the webconfig, it spawns a new
instance of your application. Existing users (those already connected) will
not see your changes and will be orphaned from your intended solution.
Changes to the web config, once in production, should be treated as a bug
fix or enhancement that required replacement of binaries.

Example

In your web.config | appsettings section, create a key pair

<Add key="ReportExportRoot" Value = "\\192.168.2.106\syn2sql$\PDF_" />
for more information on appsettings see:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpgenref/html/gngrfappsettingselement.htm

in your application's global.asax on Application_OnStart
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vbcon/html/vbconPageApplicationContext.htm
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpcontheglobalasaxfile.htm

sub application_onstart()
Dim ReportExportRoot as string
ReportExportRoot =
System.Configuration.ConfigurationSettings.AppSett ings("ReportExportRoot")
Application.Lock
Application("ReportExportRoot") = ReportExportRoot
Application.Unlock
end sub

in you application's global.asax on Session_OnStart
sub Session_Onstart()
Dim ReportExportRoot as string
Application.Lock
ReportExportRoot = ctype(Application("ReportExportRoot"),string)
Application.Unlock
Session.item("ReportExportRoot") = ReportExportRoot
end sub

"Alison Givens" <in**@cross-it.nl> wrote in message
news:OT**************@TK2MSFTNGP11.phx.gbl...
I used the code as you suggested, but again I get blue underlines.
First with every GetSessionValue,it has a blue underline:
Name GetSessionValue is not declared

and the other blue underline is GetExportRoot
myExportFile = System.IO.Path.Combine(GetExportRoot,
String.Format("PDF_{0}.pdf", myExportFile))
Says:Argument not specified for parameter 'FromApplication' of
'Private Function GetExportRoot(FromApplication As Boolean) As String'.

I pasted the code again for your convenience.

Private Enum FileNameFormats
SessionID = 0
GUIDDashes = 1
GUIDNoDashes = 2
End Enum
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
Dim myReport As RapportAIRCOStoringen
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions

Try

Try
PrepareReport(myReport)
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to prepare report.",
ex)
Throw exc
End Try

Try
'exporteren to pdf
myExportOptions =
GetExportOptions(FileNameFormats.GUIDNoDashes, CType(myReport,
CrystalDecisions.CrystalReports.Engine.ReportDocum ent).ExportOptions)
myReport.Export()

Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to export report.",
ex)
Throw exc
End Try

crViewer.ReportSource = myReport

Session("exportbestand") =
CType(myExportOptions.DestinationOptions,
CrystalDecisions.Shared.DiskFileDestinationOptions ).DiskFileName

Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try


End Sub

#End Region

#Region "Page Implementation"

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload
Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

System.IO.File.Delete(myExportFile)
End Sub

#End Region

#Region "Report Setup"

Private Sub PrepareReport(ByVal myReport As
CrystalDecisions.CrystalReports.Engine.ReportDocum ent)

Dim paramFields As ParameterFields
Dim paramField As ParameterField

Const SessionExecption As String = "Unable to read session
objects."

Try

paramFields = New ParameterFields
Try
paramField = CreateParameter("FiliaalKeuze")

paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("DiscreteValue1")))

paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("DiscreteValue1")))

Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption, ex)
Throw exc
End Try

myReport.SetParameterValue("FiliaalKeuze", paramField)

Try
'Todo wrap in try
paramField = CreateParameter("Periode")

paramField.CurrentValues.Add(CreateParameterRangeV alue(GetSessionValue("BeginPeriode"),
GetSessionValue("EindPeriode")))
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption, ex)
Throw exc
End Try

myReport.SetParameterValue("Periode", paramField)

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to set
paramatervalue.", ex)
Throw exc

End Try
End Sub

Private Function CreateParameter(ByVal ParameterName As String) As
ParameterField
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParameterName

Return paramField

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As Object,
ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function

#End Region

#Region "Report Export"

Private Function GetExportOptions(ByVal UniqueFormat As
FileNameFormats, ByVal ExportOptions As
CrystalDecisions.Shared.ExportOptions) As
CrystalDecisions.Shared.ExportOptions

Dim myExportFile As String
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
Dim myDiskFileDestinationOptions As
CrystalDecisions.Shared.DiskFileDestinationOptions

Try

Select Case UniqueFormat
Case FileNameFormats.SessionID
myExportFile = Session.SessionID.ToString
Case FileNameFormats.GUIDDashes
myExportFile = System.Guid.NewGuid.ToString("D")
Case FileNameFormats.GUIDNoDashes
myExportFile = System.Guid.NewGuid.ToString("N")
End Select

myExportFile = System.IO.Path.Combine(GetExportRoot,
String.Format("PDF_{0}.pdf", myExportFile))

myDiskFileDestinationOptions = New
CrystalDecisions.Shared.DiskFileDestinationOptions
myDiskFileDestinationOptions.DiskFileName = myExportFile

myExportOptions = ExportOptions

With myExportOptions
.DestinationOptions = myDiskFileDestinationOptions
.ExportDestinationType = .ExportDestinationType.DiskFile
.ExportFormatType = .ExportFormatType.PortableDocFormat
End With

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to prepare export
options.", ex)
Throw exc

End Try

Return myExportOptions

End Function

Private Function GetExportRoot(ByVal FromApplication As Boolean) As
String

Dim strExportRoot As String

If FromApplication Then
Try
Application.Lock()
strExportRoot = Application("ReportExportRoot")
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to lock Web
Application for read.", ex)
Throw exc
Finally
Application.UnLock()
End Try
Else
strExportRoot = Session("ReportExportRoot")
End If

Return strExportRoot

End Function

#End Region

#Region "Navigation Implementation"

Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"

Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

Response.WriteFile(myExportFile)
Response.Flush()
Response.Close()

System.IO.File.Delete(myExportFile)

End Sub

Private Sub cmdEerste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEerste.Click
crViewer.ShowFirstPage()
End Sub

Private Sub cmdLaatste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdLaatste.Click
crViewer.ShowLastPage()
End Sub

Private Sub cmdTerug_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdTerug.Click
crViewer.ShowPreviousPage()
End Sub

Private Sub cmdVerder_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdVerder.Click
crViewer.ShowNextPage()
End Sub

Private Sub drpZoom_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles drpZoom.SelectedIndexChanged
crViewer.Zoom(drpZoom.SelectedItem.Value)
End Sub

#End Region
End Class


"AMDRIT" <am****@hotmail.com> wrote in message
news:Op**************@TK2MSFTNGP09.phx.gbl...
Ok, first the isue you were having with the "Blue lines" is:

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue()
--> Retun type is expecting an array of ParameterDiscreteValue

it should be

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue
--> Retun type is expecting an single ParameterDiscreteValue

Second (Mostly because I was bored and also because I am still a novice),
I have altered your code yet again.
Private Enum FileNameFormats
SessionID = 0
GUIDDashes = 1
GUIDNoDashes = 2
End Enum

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()

Dim myReport As RapportAIRCOStoringen
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions

Try

Try
PrepareReport(myReport)
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to prepare report.", ex)
Throw exc
End Try

Try
'exporteren to pdf
myExportOptions = GetExportOptions(FileNameFormats.GUIDNoDashes,
CType(myReport,
CrystalDecisions.CrystalReports.Engine.ReportDocum ent).ExportOptions)
myReport.Export()

Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to export report.", ex)
Throw exc
End Try

crViewer.ReportSource = myReport

Session("exportbestand") = CType(myExportOptions.DestinationOptions,
CrystalDecisions.Shared.DiskFileDestinationOptions ).DiskFileName

Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try

End Sub

#Region "Page Implementation"

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload
Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

System.IO.File.Delete(myExportFile)
End Sub

#End Region

#Region "Report Setup"

Private Sub PrepareReport(ByVal myReport As
CrystalDecisions.CrystalReports.Engine.ReportDocum ent)

Dim paramFields As ParameterFields
Dim paramField As ParameterField

Const SessionExecption As String = "Unable to read session objects."

Try

paramFields = New ParameterFields
Try
paramField = CreateParameter("FiliaalKeuze")

paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("DiscreteValue1")))

paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("DiscreteValue1")))
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption, ex)
Throw exc
End Try

myReport.SetParameterValue("FiliaalKeuze", paramField)

Try
'Todo wrap in try
paramField = CreateParameter("Periode")

paramField.CurrentValues.Add(CreateParameterRangeV alue(GetSessionValue("BeginPeriode"),
GetSessionValue("EindPeriode")))
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption, ex)
Throw exc
End Try

myReport.SetParameterValue("Periode", paramField)

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to set paramater
value.", ex)
Throw exc

End Try
End Sub

Private Function CreateParameter(ByVal ParameterName As String) As
ParameterField
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParameterName

Return paramField

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue()

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

'Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As Object,
ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function

#End Region

#Region "Report Export"

Private Function GetExportOptions(ByVal UniqueFormat As FileNameFormats,
ByVal ExportOptions As CrystalDecisions.Shared.ExportOptions) As
CrystalDecisions.Shared.ExportOptions

Dim myExportFile As String
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
Dim myDiskFileDestinationOptions As
CrystalDecisions.Shared.DiskFileDestinationOptions

Try

Select Case UniqueFormat
Case FileNameFormats.SessionID
myExportFile = Session.SessionID.ToString
Case FileNameFormats.GUIDDashes
myExportFile = System.Guid.NewGuid.ToString("D")
Case FileNameFormats.GUIDNoDashes
myExportFile = System.Guid.NewGuid.ToString("N")
End Select

myExportFile = System.IO.Path.Combine(GetExportRoot,
String.Format("PDF_{0}.pdf", myExportFile))

myDiskFileDestinationOptions = New
CrystalDecisions.Shared.DiskFileDestinationOptions
myDiskFileDestinationOptions.DiskFileName = myExportFile

myExportOptions = ExportOptions

With myExportOptions
.DestinationOptions = myDiskFileDestinationOptions
.ExportDestinationType = .ExportDestinationType.DiskFile
.ExportFormatType = .ExportFormatType.PortableDocFormat
End With

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to prepare export
options.", ex)
Throw exc

End Try

Return myExportOptions

End Function

Private Function GetExportRoot(ByVal FromApplication As Boolean) As
String

Dim strExportRoot As String

If FromApplication Then
Try
Application.lock()
strExportRoot = Application("ReportExportRoot")
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to lock Web Application for
read.", ex)
Throw exc
Finally
Application.unlock()
End Try
Else
strExportRoot = Session("ReportExportRoot")
End If

Return strExportRoot

End Function

#End Region

#Region "Navigation Implementation"

Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"

Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

Response.WriteFile(myExportFile)
Response.Flush()
Response.Close()

System.IO.File.Delete(myExportFile)

End Sub

Private Sub cmdEerste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEerste.Click
crViewer.ShowFirstPage()
End Sub

Private Sub cmdLaatste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdLaatste.Click
crViewer.ShowLastPage()
End Sub

Private Sub cmdTerug_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdTerug.Click
crViewer.ShowPreviousPage()
End Sub

Private Sub cmdVerder_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdVerder.Click
crViewer.ShowNextPage()
End Sub

Private Sub drpZoom_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles drpZoom.SelectedIndexChanged
crViewer.Zoom(drpZoom.SelectedItem.Value)
End Sub

#End Region
"Alison Givens" <in**@cross-it.nl> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
Perhaps you could share your resulting code for comparison? Did you
see that I suggested the error in your code was

myReport.SetParameterValue("FiliaalKeuze", discreteVal) 'You only call
this statement once (Effectively 2344) but you wanted two values.

To get the thing going, it would be enough for me at first to know how
to call the statement twice, so the other value is forwarded too.
(btw, these two values will be SessionObjects two, but I did it
hardcoded for testing)
Best would be ofcourse that I learn to do it 'clean' of course. I am a
real newbee at this.

Here is the rest of my code:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.CrystalReports.Engine.ReportDocum ent
Imports CrystalDecisions.Shared
Imports System.IO
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()

Dim myReport As RapportAIRCOStoringen
Dim paramFields As ParameterFields
Dim paramField As ParameterField

Dim BeginPeriode As String
Dim EindPeriode As String

'Todo wrap everything in try
paramFields = New ParameterFields

Try
BeginPeriode = Request.QueryString("BeginPeriode")
EindPeriode = Request.QueryString("EindPeriode")
Catch ex As Exception
Dim exCustom As ApplicationException
exCustom = New ApplicationException("Unable to parse Query
Paramaters.", ex)
Throw exCustom
End Try

'Todo wrap in try
paramField = CreateParameter("FiliaalKeuze")
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2044))
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2344))
myReport.SetParameterValue("FiliaalKeuze", paramField)
'Todo wrap in try
paramField = CreateParameter("Periode")

paramField.CurrentValues.Add(CreateParameterRangeV alue(BeginPeriode,
EindPeriode))
myReport.SetParameterValue("Periode", paramField)
crViewer.ReportSource = myReport
'exporteren to pdf
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
Dim myDiskFileDestinationOptions As
CrystalDecisions.Shared.DiskFileDestinationOptions
Dim myExportFile As String

myExportFile = "\\192.168.2.106\syn2sql$\PDF_" &
Session.SessionID.ToString & ".pdf"
myDiskFileDestinationOptions = New
CrystalDecisions.Shared.DiskFileDestinationOptions
myDiskFileDestinationOptions.DiskFileName = myExportFile
myExportOptions = myReport.ExportOptions
With myExportOptions
.DestinationOptions = myDiskFileDestinationOptions
.ExportDestinationType = .ExportDestinationType.DiskFile
.ExportFormatType = .ExportFormatType.PortableDocFormat
End With

Try
myReport.Export()
Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try

Session("exportbestand") = myExportFile
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

Response.WriteFile(myExportFile)
Response.Flush()
Response.Close()

System.IO.File.Delete(myExportFile)
End Sub

Private Function CreateParameter(ByVal ParameterName As String) As
ParameterField()
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParameterName

'Return paramField

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object)
As ParameterDiscreteValue()

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

'Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As
Object, ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function
Private Sub cmdEerste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEerste.Click
crViewer.ShowFirstPage()
End Sub

Private Sub cmdLaatste_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdLaatste.Click
crViewer.ShowLastPage()
End Sub

Private Sub cmdTerug_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdTerug.Click
crViewer.ShowPreviousPage()
End Sub

Private Sub cmdVerder_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdVerder.Click
crViewer.ShowNextPage()
End Sub

Private Sub drpZoom_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles drpZoom.SelectedIndexChanged
crViewer.Zoom(drpZoom.SelectedItem.Value)
End Sub
Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload
Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

System.IO.File.Delete(myExportFile)
End Sub
End Class



"Alison Givens" <in**@cross-it.nl> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
> When I use your solution I get blue lines under the text like this
>
> paramField = CreateParamater("FiliaalKeuze")
> The text is:
> Value of type '1 dimensional array of
> CrystalDecisions.Shared.ParameterField' cannot be converted
> to 'Crystal.Decisions.Shared.ParameterField'
>
> Return paramField
> The text is:
> Value of type 'CrystalDecisions.Shared.ParameterField' cannot be
> converted
> to '1 dimensional array of Crystal.Decisions.Shared.ParameterField'
>
> Same for
> paramField = CreateParamater("Periode")
> Return paramDiscreteValue
>
> Any idea what causes this?
>
> Alison
>
>
> "AMDRIT" <am****@hotmail.com> wrote in message
> news:ur*************@TK2MSFTNGP14.phx.gbl...
>> Wow, you do all that for Crystal Reports? What is
>> RapportAIRCOStoringen?
>>
>>
>> Here is all I do for CR
>>
>> Dim x As CrystalDecisions.CrystalReports.Engine.ReportDocum ent
>>
>> x.Load(sReportPath) 'Reports are not embedded resources
>> x.SetParameterValue("Paramater1", Paramaters(1)) 'Dynamic
>> Paramaters
>> x.SetParameterValue("Paramater2", Paramaters(2))
>> x.SetDataSource(mydata) 'Strongly Typed Datasets
>>
>> Me.CrystalReportViewer1.ReportSource = x
>> Me.CrystalReportViewer1.PrintReport()
>>
>>
>> 'Now to answer your question about your code, hmm
>>
>> Ok, first
>>
>> Never --> Dim x as new object
>> 'This is silly, lazy and unprofessional. So if you are in
>> high school, keep the course.
>>
>>
>> Instead --> Dim x as object
>> Set x = new object
>> 'Reserve your space and contract
>> 'Then make use of it.
>>
>> I think this is your problem
>>
>> myReport.SetParameterValue("FiliaalKeuze", discreteVal)
>>
>> Why are you setting the crView paramaters and the myReport
>> paramaters?
>> -->crViewer.ParameterFieldInfo = paramFields
>> -->myReport.SetParameterValue("Periode", rangeVal)
>>
>> I think that myReport is the only think that needs to be set
>>
>>
>> I had to spent time reading your code to understand what you were
>> doing.
>>
>> Here is an attempt to clean it up.
>>
>> Private Sub TestIT()
>>
>> Dim myReport As RapportAIRCOStoringen
>> Dim paramFields As ParameterFields
>> Dim paramField As ParameterField
>>
>> Dim BeginPeriode As String
>> Dim EindPeriode As String
>>
>> 'Todo wrap everything in try
>> paramFields = New ParameterFields
>>
>> Try
>> BeginPeriode = Request.QueryString("BeginPeriode")
>> EindPeriode = Request.QueryString("EindPeriode")
>> Catch ex As Exception
>> Dim exCustom As ApplicationException
>> exCustom = New ApplicationException("Unable to parse Query
>> Paramaters.", ex)
>> Throw exCustom
>> End Try
>>
>> 'Todo wrap in try
>> paramField = CreateParamater("FiliaalKeuze")
>> paramField.CurrentValues.Add(CreateParameterDiscre teValue(2044))
>> paramField.CurrentValues.Add(CreateParameterDiscre teValue(2344))
>> myReport.SetParameterValue("FiliaalKeuze", paramField)
>> 'paramFields.Add(paramField) --> Not needed
>>
>> 'Todo wrap in try
>> paramField = CreateParamater("Periode")
>>
>> paramField.CurrentValues.Add(CreateParameterRangeV alue(BeginPeriode,
>> EindPeriode))
>> myReport.SetParameterValue("Periode", paramField)
>> 'paramFields.Add(paramField)--> Not needed
>>
>> 'Todo wrap in try, i don't think you need this
>> 'myReport.SetParameterValue("Periode", rangeVal)
>> 'myReport.SetParameterValue("FiliaalKeuze", discreteVal)
>>
>> 'Todo, determine if we need this step; I don't think you do
>> 'crViewer.ParameterFieldInfo = paramFields
>>
>> crViewer.ReportSource = myReport
>>
>> End Sub
>>
>> Private Function CreateParamater(ByVal ParamaterName As String) As
>> ParameterField
>> Dim paramField As ParameterField
>>
>> paramField = New ParameterField
>> paramField.ParameterFieldName = ParamaterName
>>
>> Return paramField
>>
>> End Function
>>
>> Private Function CreateParameterDiscreteValue(ByVal Value As Object)
>> As ParameterDiscreteValue
>>
>> Dim paramDiscreteValue As ParameterDiscreteValue
>> paramDiscreteValue = New ParameterDiscreteValue
>> paramDiscreteValue = Value
>>
>> Return paramDiscreteValue
>>
>> End Function
>>
>> Private Function CreateParameterRangeValue(ByVal StartRange As
>> Object, ByVal EndRange As Object) As ParameterRangeValue
>> Dim paramRangeValue As ParameterRangeValue
>>
>> paramRangeValue = New ParameterRangeValue
>>
>> paramRangeValue.StartValue = StartRange
>> paramRangeValue.EndValue = EndRange
>>
>> Return paramRangeValue
>> End Function
>>
>> "Alison Givens" <in**@cross-it.nl> wrote in message
>> news:eW*************@TK2MSFTNGP11.phx.gbl...
>>> ...... that nobody knows the answer.
>>> I can't imagine that I am the only one that uses parameters in CR.
>>>
>>> So, my question again:
>>>
>>> I have the following problem.
>>> (VB.NET 2003 with CR)
>>>
>>> I have a report with a multiple-value discrete value and a
>>> rangevalue.
>>> The report shows fine in the viewer, but when I hit the export to
>>> pdf
>>> button, it only uses one of two discrete values.
>>>
>>> This is the code:
>>> Dim BeginPeriode As String
>>> Dim EindPeriode As String
>>>
>>> BeginPeriode = Request.QueryString("BeginPeriode")
>>> EindPeriode = Request.QueryString("EindPeriode")
>>>
>>> Dim myReport As New RapportAIRCOStoringen
>>>
>>> Dim paramFields As New ParameterFields
>>> Dim paramField As New ParameterField
>>> Dim discreteVal As New ParameterDiscreteValue
>>> Dim rangeVal As New ParameterRangeValue
>>>
>>> paramField.ParameterFieldName = "FiliaalKeuze"
>>> discreteVal.Value = "2044"
>>> paramField.CurrentValues.Add(discreteVal)
>>>
>>> discreteVal = New ParameterDiscreteValue
>>> discreteVal.Value = "2344"
>>> paramField.CurrentValues.Add(discreteVal)
>>>
>>> paramFields.Add(paramField)
>>>
>>> paramField = New ParameterField
>>>
>>> paramField.ParameterFieldName = "Periode"
>>>
>>> rangeVal.StartValue = BeginPeriode
>>> rangeVal.EndValue = EindPeriode
>>> paramField.CurrentValues.Add(rangeVal)
>>>
>>> paramFields.Add(paramField)
>>>
>>> crViewer.ParameterFieldInfo = paramFields
>>> myReport.SetParameterValue("Periode", rangeVal)
>>> myReport.SetParameterValue("FiliaalKeuze", discreteVal)
>>> crViewer.ReportSource = myReport
>>>
>>> As you can see I use myReport.SetParameterValue to feed the pdf.
>>> It goes wrong with the discrete value. It only sees the second value
>>> I
>>> entered and not the first.
>>> How can I get this going?
>>>
>>>
>>> Kind regards,
>>> Alison
>>>
>>>
>>>
>>>
>>
>>
>
>



Feb 21 '06 #8
Ok, to the next level.
I put the Add key in the web.config
It comes with an error as shown here.
Configuration Error
Description: An error occurred during the processing of a configuration file
required to service this request. Please review the specific error details
below and modify your configuration file appropriately.

Parser Error Message: Unrecognized element

Source Error:
Line 2: <configuration>
Line 3: <appSettings>
Line 4: <Add key="ReportExportRoot" Value
="\\192.168.2.106\syn2sql$\PDF_" />
Line 5: </appSettings>
Line 6: <system.web>
I did all the other things aswell, as you described.
I have a question though about the GetSession.
Is the code allright, as I placed here?

Private Function GetSessionValue(ByVal KeyName As String) As Object
Return Session.Item(KeyName)
End Function

I really appreciate your help, but since I am a real greenhorn, I hope you
are not going to fast for me.

Alison


"AMDRIT" <am****@hotmail.com> wrote in message
news:OY*************@TK2MSFTNGP15.phx.gbl...
Good morning,

I just realized you keep different hours than me. Please keep in mind
that all the code that I have submitted to you is wholly untested and
therefore the jist of what I was conveying should be taken into context.
I attempt to answer your direct question before going off onto a tangent.

1. You need a function named GetSessionValue
The signature would look like: GetSessionValue(KeyName as string) as
object and all it would do is return Session.Item(KeyName)

2. Correct the line
myExportFile = System.IO.Path.Combine(GetExportRoot,
String.Format("PDF_{0}.pdf", myExportFile))
to
myExportFile = System.IO.Path.Combine(GetExportRoot(false),
String.Format("PDF_{0}.pdf", myExportFile))
or
myExportFile = System.IO.Path.Combine(GetExportRoot(true),
String.Format("PDF_{0}.pdf", myExportFile))

If you are to use the function GetExportRoot, then you must set up your
global.asax to set a global variable to hold ReportExportRoot in
Application_OnStart, and if you want each session to get a copy of that
value in the global.asax Session_OnStart, have it read the Application
variable.

The goal here is to store environmental setting information out of
compiled code. It's more work to set it up, but will not require you to
compile the application everytime you want to make a change.

ideal uses for the web config (DbConnection, ServerLocations, FileShares,
WebService URLs)

keep in mind though, each time you modify the webconfig, it spawns a new
instance of your application. Existing users (those already connected)
will not see your changes and will be orphaned from your intended
solution. Changes to the web config, once in production, should be treated
as a bug fix or enhancement that required replacement of binaries.

Example

In your web.config | appsettings section, create a key pair

<Add key="ReportExportRoot" Value = "\\192.168.2.106\syn2sql$\PDF_" />
for more information on appsettings see:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpgenref/html/gngrfappsettingselement.htm

in your application's global.asax on Application_OnStart
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vbcon/html/vbconPageApplicationContext.htm
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpcontheglobalasaxfile.htm

sub application_onstart()
Dim ReportExportRoot as string
ReportExportRoot =
System.Configuration.ConfigurationSettings.AppSett ings("ReportExportRoot")
Application.Lock
Application("ReportExportRoot") = ReportExportRoot
Application.Unlock
end sub

in you application's global.asax on Session_OnStart
sub Session_Onstart()
Dim ReportExportRoot as string
Application.Lock
ReportExportRoot = ctype(Application("ReportExportRoot"),string)
Application.Unlock
Session.item("ReportExportRoot") = ReportExportRoot
end sub

"Alison Givens" <in**@cross-it.nl> wrote in message
news:OT**************@TK2MSFTNGP11.phx.gbl...
I used the code as you suggested, but again I get blue underlines.
First with every GetSessionValue,it has a blue underline:
Name GetSessionValue is not declared

and the other blue underline is GetExportRoot
myExportFile = System.IO.Path.Combine(GetExportRoot,
String.Format("PDF_{0}.pdf", myExportFile))
Says:Argument not specified for parameter 'FromApplication' of
'Private Function GetExportRoot(FromApplication As Boolean) As String'.

I pasted the code again for your convenience.

Private Enum FileNameFormats
SessionID = 0
GUIDDashes = 1
GUIDNoDashes = 2
End Enum
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
Dim myReport As RapportAIRCOStoringen
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions

Try

Try
PrepareReport(myReport)
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to prepare
report.", ex)
Throw exc
End Try

Try
'exporteren to pdf
myExportOptions =
GetExportOptions(FileNameFormats.GUIDNoDashes, CType(myReport,
CrystalDecisions.CrystalReports.Engine.ReportDocum ent).ExportOptions)
myReport.Export()

Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to export report.",
ex)
Throw exc
End Try

crViewer.ReportSource = myReport

Session("exportbestand") =
CType(myExportOptions.DestinationOptions,
CrystalDecisions.Shared.DiskFileDestinationOptions ).DiskFileName

Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try


End Sub

#End Region

#Region "Page Implementation"

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload
Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

System.IO.File.Delete(myExportFile)
End Sub

#End Region

#Region "Report Setup"

Private Sub PrepareReport(ByVal myReport As
CrystalDecisions.CrystalReports.Engine.ReportDocum ent)

Dim paramFields As ParameterFields
Dim paramField As ParameterField

Const SessionExecption As String = "Unable to read session
objects."

Try

paramFields = New ParameterFields
Try
paramField = CreateParameter("FiliaalKeuze")

paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("DiscreteValue1")))

paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("DiscreteValue1")))

Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption,
ex)
Throw exc
End Try

myReport.SetParameterValue("FiliaalKeuze", paramField)

Try
'Todo wrap in try
paramField = CreateParameter("Periode")

paramField.CurrentValues.Add(CreateParameterRangeV alue(GetSessionValue("BeginPeriode"),
GetSessionValue("EindPeriode")))
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption,
ex)
Throw exc
End Try

myReport.SetParameterValue("Periode", paramField)

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to set
paramatervalue.", ex)
Throw exc

End Try
End Sub

Private Function CreateParameter(ByVal ParameterName As String) As
ParameterField
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParameterName

Return paramField

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object)
As ParameterDiscreteValue

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As Object,
ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function

#End Region

#Region "Report Export"

Private Function GetExportOptions(ByVal UniqueFormat As
FileNameFormats, ByVal ExportOptions As
CrystalDecisions.Shared.ExportOptions) As
CrystalDecisions.Shared.ExportOptions

Dim myExportFile As String
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
Dim myDiskFileDestinationOptions As
CrystalDecisions.Shared.DiskFileDestinationOptions

Try

Select Case UniqueFormat
Case FileNameFormats.SessionID
myExportFile = Session.SessionID.ToString
Case FileNameFormats.GUIDDashes
myExportFile = System.Guid.NewGuid.ToString("D")
Case FileNameFormats.GUIDNoDashes
myExportFile = System.Guid.NewGuid.ToString("N")
End Select

myExportFile = System.IO.Path.Combine(GetExportRoot,
String.Format("PDF_{0}.pdf", myExportFile))

myDiskFileDestinationOptions = New
CrystalDecisions.Shared.DiskFileDestinationOptions
myDiskFileDestinationOptions.DiskFileName = myExportFile

myExportOptions = ExportOptions

With myExportOptions
.DestinationOptions = myDiskFileDestinationOptions
.ExportDestinationType = .ExportDestinationType.DiskFile
.ExportFormatType = .ExportFormatType.PortableDocFormat
End With

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to prepare
export options.", ex)
Throw exc

End Try

Return myExportOptions

End Function

Private Function GetExportRoot(ByVal FromApplication As Boolean) As
String

Dim strExportRoot As String

If FromApplication Then
Try
Application.Lock()
strExportRoot = Application("ReportExportRoot")
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to lock Web
Application for read.", ex)
Throw exc
Finally
Application.UnLock()
End Try
Else
strExportRoot = Session("ReportExportRoot")
End If

Return strExportRoot

End Function

#End Region

#Region "Navigation Implementation"

Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"

Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

Response.WriteFile(myExportFile)
Response.Flush()
Response.Close()

System.IO.File.Delete(myExportFile)

End Sub

Private Sub cmdEerste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEerste.Click
crViewer.ShowFirstPage()
End Sub

Private Sub cmdLaatste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdLaatste.Click
crViewer.ShowLastPage()
End Sub

Private Sub cmdTerug_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdTerug.Click
crViewer.ShowPreviousPage()
End Sub

Private Sub cmdVerder_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdVerder.Click
crViewer.ShowNextPage()
End Sub

Private Sub drpZoom_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles drpZoom.SelectedIndexChanged
crViewer.Zoom(drpZoom.SelectedItem.Value)
End Sub

#End Region
End Class


"AMDRIT" <am****@hotmail.com> wrote in message
news:Op**************@TK2MSFTNGP09.phx.gbl...
Ok, first the isue you were having with the "Blue lines" is:

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue()
--> Retun type is expecting an array of ParameterDiscreteValue

it should be

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue
--> Retun type is expecting an single ParameterDiscreteValue

Second (Mostly because I was bored and also because I am still a
novice), I have altered your code yet again.
Private Enum FileNameFormats
SessionID = 0
GUIDDashes = 1
GUIDNoDashes = 2
End Enum

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()

Dim myReport As RapportAIRCOStoringen
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions

Try

Try
PrepareReport(myReport)
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to prepare report.", ex)
Throw exc
End Try

Try
'exporteren to pdf
myExportOptions = GetExportOptions(FileNameFormats.GUIDNoDashes,
CType(myReport,
CrystalDecisions.CrystalReports.Engine.ReportDocum ent).ExportOptions)
myReport.Export()

Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to export report.", ex)
Throw exc
End Try

crViewer.ReportSource = myReport

Session("exportbestand") =
CType(myExportOptions.DestinationOptions,
CrystalDecisions.Shared.DiskFileDestinationOptions ).DiskFileName

Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try

End Sub

#Region "Page Implementation"

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload
Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

System.IO.File.Delete(myExportFile)
End Sub

#End Region

#Region "Report Setup"

Private Sub PrepareReport(ByVal myReport As
CrystalDecisions.CrystalReports.Engine.ReportDocum ent)

Dim paramFields As ParameterFields
Dim paramField As ParameterField

Const SessionExecption As String = "Unable to read session objects."

Try

paramFields = New ParameterFields
Try
paramField = CreateParameter("FiliaalKeuze")

paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("DiscreteValue1")))

paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("DiscreteValue1")))
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption, ex)
Throw exc
End Try

myReport.SetParameterValue("FiliaalKeuze", paramField)

Try
'Todo wrap in try
paramField = CreateParameter("Periode")

paramField.CurrentValues.Add(CreateParameterRangeV alue(GetSessionValue("BeginPeriode"),
GetSessionValue("EindPeriode")))
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption, ex)
Throw exc
End Try

myReport.SetParameterValue("Periode", paramField)

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to set paramater
value.", ex)
Throw exc

End Try
End Sub

Private Function CreateParameter(ByVal ParameterName As String) As
ParameterField
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParameterName

Return paramField

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue()

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

'Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As Object,
ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function

#End Region

#Region "Report Export"

Private Function GetExportOptions(ByVal UniqueFormat As
FileNameFormats, ByVal ExportOptions As
CrystalDecisions.Shared.ExportOptions) As
CrystalDecisions.Shared.ExportOptions

Dim myExportFile As String
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
Dim myDiskFileDestinationOptions As
CrystalDecisions.Shared.DiskFileDestinationOptions

Try

Select Case UniqueFormat
Case FileNameFormats.SessionID
myExportFile = Session.SessionID.ToString
Case FileNameFormats.GUIDDashes
myExportFile = System.Guid.NewGuid.ToString("D")
Case FileNameFormats.GUIDNoDashes
myExportFile = System.Guid.NewGuid.ToString("N")
End Select

myExportFile = System.IO.Path.Combine(GetExportRoot,
String.Format("PDF_{0}.pdf", myExportFile))

myDiskFileDestinationOptions = New
CrystalDecisions.Shared.DiskFileDestinationOptions
myDiskFileDestinationOptions.DiskFileName = myExportFile

myExportOptions = ExportOptions

With myExportOptions
.DestinationOptions = myDiskFileDestinationOptions
.ExportDestinationType = .ExportDestinationType.DiskFile
.ExportFormatType = .ExportFormatType.PortableDocFormat
End With

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to prepare export
options.", ex)
Throw exc

End Try

Return myExportOptions

End Function

Private Function GetExportRoot(ByVal FromApplication As Boolean) As
String

Dim strExportRoot As String

If FromApplication Then
Try
Application.lock()
strExportRoot = Application("ReportExportRoot")
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to lock Web Application
for read.", ex)
Throw exc
Finally
Application.unlock()
End Try
Else
strExportRoot = Session("ReportExportRoot")
End If

Return strExportRoot

End Function

#End Region

#Region "Navigation Implementation"

Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"

Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

Response.WriteFile(myExportFile)
Response.Flush()
Response.Close()

System.IO.File.Delete(myExportFile)

End Sub

Private Sub cmdEerste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEerste.Click
crViewer.ShowFirstPage()
End Sub

Private Sub cmdLaatste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdLaatste.Click
crViewer.ShowLastPage()
End Sub

Private Sub cmdTerug_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdTerug.Click
crViewer.ShowPreviousPage()
End Sub

Private Sub cmdVerder_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdVerder.Click
crViewer.ShowNextPage()
End Sub

Private Sub drpZoom_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles drpZoom.SelectedIndexChanged
crViewer.Zoom(drpZoom.SelectedItem.Value)
End Sub

#End Region
"Alison Givens" <in**@cross-it.nl> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
> Perhaps you could share your resulting code for comparison? Did you
> see that I suggested the error in your code was
>
> myReport.SetParameterValue("FiliaalKeuze", discreteVal) 'You only call
> this statement once (Effectively 2344) but you wanted two values.

To get the thing going, it would be enough for me at first to know how
to call the statement twice, so the other value is forwarded too.
(btw, these two values will be SessionObjects two, but I did it
hardcoded for testing)
Best would be ofcourse that I learn to do it 'clean' of course. I am a
real newbee at this.

Here is the rest of my code:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.CrystalReports.Engine.ReportDocum ent
Imports CrystalDecisions.Shared
Imports System.IO
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()

Dim myReport As RapportAIRCOStoringen
Dim paramFields As ParameterFields
Dim paramField As ParameterField

Dim BeginPeriode As String
Dim EindPeriode As String

'Todo wrap everything in try
paramFields = New ParameterFields

Try
BeginPeriode = Request.QueryString("BeginPeriode")
EindPeriode = Request.QueryString("EindPeriode")
Catch ex As Exception
Dim exCustom As ApplicationException
exCustom = New ApplicationException("Unable to parse Query
Paramaters.", ex)
Throw exCustom
End Try

'Todo wrap in try
paramField = CreateParameter("FiliaalKeuze")
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2044))
paramField.CurrentValues.Add(CreateParameterDiscre teValue(2344))
myReport.SetParameterValue("FiliaalKeuze", paramField)
'Todo wrap in try
paramField = CreateParameter("Periode")

paramField.CurrentValues.Add(CreateParameterRangeV alue(BeginPeriode,
EindPeriode))
myReport.SetParameterValue("Periode", paramField)
crViewer.ReportSource = myReport
'exporteren to pdf
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
Dim myDiskFileDestinationOptions As
CrystalDecisions.Shared.DiskFileDestinationOptions
Dim myExportFile As String

myExportFile = "\\192.168.2.106\syn2sql$\PDF_" &
Session.SessionID.ToString & ".pdf"
myDiskFileDestinationOptions = New
CrystalDecisions.Shared.DiskFileDestinationOptions
myDiskFileDestinationOptions.DiskFileName = myExportFile
myExportOptions = myReport.ExportOptions
With myExportOptions
.DestinationOptions = myDiskFileDestinationOptions
.ExportDestinationType = .ExportDestinationType.DiskFile
.ExportFormatType = .ExportFormatType.PortableDocFormat
End With

Try
myReport.Export()
Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try

Session("exportbestand") = myExportFile
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Dim myExportFile As String =
CType(Session.Item("exportbestand"), String)

Response.WriteFile(myExportFile)
Response.Flush()
Response.Close()

System.IO.File.Delete(myExportFile)
End Sub

Private Function CreateParameter(ByVal ParameterName As String) As
ParameterField()
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParameterName

'Return paramField

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object)
As ParameterDiscreteValue()

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

'Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As
Object, ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function
Private Sub cmdEerste_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdEerste.Click
crViewer.ShowFirstPage()
End Sub

Private Sub cmdLaatste_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdLaatste.Click
crViewer.ShowLastPage()
End Sub

Private Sub cmdTerug_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdTerug.Click
crViewer.ShowPreviousPage()
End Sub

Private Sub cmdVerder_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdVerder.Click
crViewer.ShowNextPage()
End Sub

Private Sub drpZoom_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles drpZoom.SelectedIndexChanged
crViewer.Zoom(drpZoom.SelectedItem.Value)
End Sub
Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload
Dim myExportFile As String =
CType(Session.Item("exportbestand"), String)

System.IO.File.Delete(myExportFile)
End Sub
End Class


>
> "Alison Givens" <in**@cross-it.nl> wrote in message
> news:ee**************@TK2MSFTNGP09.phx.gbl...
>> When I use your solution I get blue lines under the text like this
>>
>> paramField = CreateParamater("FiliaalKeuze")
>> The text is:
>> Value of type '1 dimensional array of
>> CrystalDecisions.Shared.ParameterField' cannot be converted
>> to 'Crystal.Decisions.Shared.ParameterField'
>>
>> Return paramField
>> The text is:
>> Value of type 'CrystalDecisions.Shared.ParameterField' cannot be
>> converted
>> to '1 dimensional array of Crystal.Decisions.Shared.ParameterField'
>>
>> Same for
>> paramField = CreateParamater("Periode")
>> Return paramDiscreteValue
>>
>> Any idea what causes this?
>>
>> Alison
>>
>>
>> "AMDRIT" <am****@hotmail.com> wrote in message
>> news:ur*************@TK2MSFTNGP14.phx.gbl...
>>> Wow, you do all that for Crystal Reports? What is
>>> RapportAIRCOStoringen?
>>>
>>>
>>> Here is all I do for CR
>>>
>>> Dim x As CrystalDecisions.CrystalReports.Engine.ReportDocum ent
>>>
>>> x.Load(sReportPath) 'Reports are not embedded resources
>>> x.SetParameterValue("Paramater1", Paramaters(1)) 'Dynamic
>>> Paramaters
>>> x.SetParameterValue("Paramater2", Paramaters(2))
>>> x.SetDataSource(mydata) 'Strongly Typed Datasets
>>>
>>> Me.CrystalReportViewer1.ReportSource = x
>>> Me.CrystalReportViewer1.PrintReport()
>>>
>>>
>>> 'Now to answer your question about your code, hmm
>>>
>>> Ok, first
>>>
>>> Never --> Dim x as new object
>>> 'This is silly, lazy and unprofessional. So if you are in
>>> high school, keep the course.
>>>
>>>
>>> Instead --> Dim x as object
>>> Set x = new object
>>> 'Reserve your space and contract
>>> 'Then make use of it.
>>>
>>> I think this is your problem
>>>
>>> myReport.SetParameterValue("FiliaalKeuze", discreteVal)
>>>
>>> Why are you setting the crView paramaters and the myReport
>>> paramaters?
>>> -->crViewer.ParameterFieldInfo = paramFields
>>> -->myReport.SetParameterValue("Periode", rangeVal)
>>>
>>> I think that myReport is the only think that needs to be set
>>>
>>>
>>> I had to spent time reading your code to understand what you were
>>> doing.
>>>
>>> Here is an attempt to clean it up.
>>>
>>> Private Sub TestIT()
>>>
>>> Dim myReport As RapportAIRCOStoringen
>>> Dim paramFields As ParameterFields
>>> Dim paramField As ParameterField
>>>
>>> Dim BeginPeriode As String
>>> Dim EindPeriode As String
>>>
>>> 'Todo wrap everything in try
>>> paramFields = New ParameterFields
>>>
>>> Try
>>> BeginPeriode = Request.QueryString("BeginPeriode")
>>> EindPeriode = Request.QueryString("EindPeriode")
>>> Catch ex As Exception
>>> Dim exCustom As ApplicationException
>>> exCustom = New ApplicationException("Unable to parse Query
>>> Paramaters.", ex)
>>> Throw exCustom
>>> End Try
>>>
>>> 'Todo wrap in try
>>> paramField = CreateParamater("FiliaalKeuze")
>>> paramField.CurrentValues.Add(CreateParameterDiscre teValue(2044))
>>> paramField.CurrentValues.Add(CreateParameterDiscre teValue(2344))
>>> myReport.SetParameterValue("FiliaalKeuze", paramField)
>>> 'paramFields.Add(paramField) --> Not needed
>>>
>>> 'Todo wrap in try
>>> paramField = CreateParamater("Periode")
>>>
>>> paramField.CurrentValues.Add(CreateParameterRangeV alue(BeginPeriode,
>>> EindPeriode))
>>> myReport.SetParameterValue("Periode", paramField)
>>> 'paramFields.Add(paramField)--> Not needed
>>>
>>> 'Todo wrap in try, i don't think you need this
>>> 'myReport.SetParameterValue("Periode", rangeVal)
>>> 'myReport.SetParameterValue("FiliaalKeuze", discreteVal)
>>>
>>> 'Todo, determine if we need this step; I don't think you do
>>> 'crViewer.ParameterFieldInfo = paramFields
>>>
>>> crViewer.ReportSource = myReport
>>>
>>> End Sub
>>>
>>> Private Function CreateParamater(ByVal ParamaterName As String) As
>>> ParameterField
>>> Dim paramField As ParameterField
>>>
>>> paramField = New ParameterField
>>> paramField.ParameterFieldName = ParamaterName
>>>
>>> Return paramField
>>>
>>> End Function
>>>
>>> Private Function CreateParameterDiscreteValue(ByVal Value As
>>> Object) As ParameterDiscreteValue
>>>
>>> Dim paramDiscreteValue As ParameterDiscreteValue
>>> paramDiscreteValue = New ParameterDiscreteValue
>>> paramDiscreteValue = Value
>>>
>>> Return paramDiscreteValue
>>>
>>> End Function
>>>
>>> Private Function CreateParameterRangeValue(ByVal StartRange As
>>> Object, ByVal EndRange As Object) As ParameterRangeValue
>>> Dim paramRangeValue As ParameterRangeValue
>>>
>>> paramRangeValue = New ParameterRangeValue
>>>
>>> paramRangeValue.StartValue = StartRange
>>> paramRangeValue.EndValue = EndRange
>>>
>>> Return paramRangeValue
>>> End Function
>>>
>>> "Alison Givens" <in**@cross-it.nl> wrote in message
>>> news:eW*************@TK2MSFTNGP11.phx.gbl...
>>>> ...... that nobody knows the answer.
>>>> I can't imagine that I am the only one that uses parameters in CR.
>>>>
>>>> So, my question again:
>>>>
>>>> I have the following problem.
>>>> (VB.NET 2003 with CR)
>>>>
>>>> I have a report with a multiple-value discrete value and a
>>>> rangevalue.
>>>> The report shows fine in the viewer, but when I hit the export to
>>>> pdf
>>>> button, it only uses one of two discrete values.
>>>>
>>>> This is the code:
>>>> Dim BeginPeriode As String
>>>> Dim EindPeriode As String
>>>>
>>>> BeginPeriode = Request.QueryString("BeginPeriode")
>>>> EindPeriode = Request.QueryString("EindPeriode")
>>>>
>>>> Dim myReport As New RapportAIRCOStoringen
>>>>
>>>> Dim paramFields As New ParameterFields
>>>> Dim paramField As New ParameterField
>>>> Dim discreteVal As New ParameterDiscreteValue
>>>> Dim rangeVal As New ParameterRangeValue
>>>>
>>>> paramField.ParameterFieldName = "FiliaalKeuze"
>>>> discreteVal.Value = "2044"
>>>> paramField.CurrentValues.Add(discreteVal)
>>>>
>>>> discreteVal = New ParameterDiscreteValue
>>>> discreteVal.Value = "2344"
>>>> paramField.CurrentValues.Add(discreteVal)
>>>>
>>>> paramFields.Add(paramField)
>>>>
>>>> paramField = New ParameterField
>>>>
>>>> paramField.ParameterFieldName = "Periode"
>>>>
>>>> rangeVal.StartValue = BeginPeriode
>>>> rangeVal.EndValue = EindPeriode
>>>> paramField.CurrentValues.Add(rangeVal)
>>>>
>>>> paramFields.Add(paramField)
>>>>
>>>> crViewer.ParameterFieldInfo = paramFields
>>>> myReport.SetParameterValue("Periode", rangeVal)
>>>> myReport.SetParameterValue("FiliaalKeuze", discreteVal)
>>>> crViewer.ReportSource = myReport
>>>>
>>>> As you can see I use myReport.SetParameterValue to feed the pdf.
>>>> It goes wrong with the discrete value. It only sees the second
>>>> value I
>>>> entered and not the first.
>>>> How can I get this going?
>>>>
>>>>
>>>> Kind regards,
>>>> Alison
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>



Feb 22 '06 #9
Perhaps web.config is case sensitive.

<configuration>
<appSettings>
<add key="ReportExportRoot" value="\\192.168.2.106\syn2sql$\PDF_" />
</appSettings>
</configuration>

works for me, however notice add, key, and value are lower case. try that.

Your function is fine, perhaps you would like to spice it up a bit. (it is
really up to you and the amount of error handeling you would like.)
Private Function GetSessionValue(ByVal KeyName As String) As Object try Return Session.Item(KeyName) catch ex as exception
dim exc as applicationexception
exc = new applicationexception(string.format("Unable to read value from
session:{0}",KeyName),ex)
throw exc
end try End Function
there is a great series of webcasts on the MS Events site. The series was
presented by Joe Hummel, you should have a look at them. Here is a link to
get you started, the best part is that they are free.

http://www.microsoft.com/events/Even...taSvcParams%5e

or just go to msdn.microsoft.com/events, choose webcasts | Ondemand
webcasts. and then search for topics of interest. Many are .Net 1.1
related but the concepts carry forward to .Net 2.0.

If you have more questions, just drop a post here.

"Alison Givens" <in**@cross-it.nl> wrote in message
news:uV*************@TK2MSFTNGP15.phx.gbl... Ok, to the next level.
I put the Add key in the web.config
It comes with an error as shown here.
Configuration Error
Description: An error occurred during the processing of a configuration
file required to service this request. Please review the specific error
details below and modify your configuration file appropriately.

Parser Error Message: Unrecognized element

Source Error:
Line 2: <configuration>
Line 3: <appSettings>
Line 4: <Add key="ReportExportRoot" Value
="\\192.168.2.106\syn2sql$\PDF_" />
Line 5: </appSettings>
Line 6: <system.web>
I did all the other things aswell, as you described.
I have a question though about the GetSession.
Is the code allright, as I placed here?

Private Function GetSessionValue(ByVal KeyName As String) As Object
Return Session.Item(KeyName)
End Function

I really appreciate your help, but since I am a real greenhorn, I hope you
are not going to fast for me.

Alison


"AMDRIT" <am****@hotmail.com> wrote in message
news:OY*************@TK2MSFTNGP15.phx.gbl...
Good morning,

I just realized you keep different hours than me. Please keep in mind
that all the code that I have submitted to you is wholly untested and
therefore the jist of what I was conveying should be taken into context.
I attempt to answer your direct question before going off onto a tangent.

1. You need a function named GetSessionValue
The signature would look like: GetSessionValue(KeyName as string) as
object and all it would do is return Session.Item(KeyName)

2. Correct the line
myExportFile = System.IO.Path.Combine(GetExportRoot,
String.Format("PDF_{0}.pdf", myExportFile))
to
myExportFile = System.IO.Path.Combine(GetExportRoot(false),
String.Format("PDF_{0}.pdf", myExportFile))
or
myExportFile = System.IO.Path.Combine(GetExportRoot(true),
String.Format("PDF_{0}.pdf", myExportFile))

If you are to use the function GetExportRoot, then you must set up your
global.asax to set a global variable to hold ReportExportRoot in
Application_OnStart, and if you want each session to get a copy of that
value in the global.asax Session_OnStart, have it read the Application
variable.

The goal here is to store environmental setting information out of
compiled code. It's more work to set it up, but will not require you to
compile the application everytime you want to make a change.

ideal uses for the web config (DbConnection, ServerLocations, FileShares,
WebService URLs)

keep in mind though, each time you modify the webconfig, it spawns a new
instance of your application. Existing users (those already connected)
will not see your changes and will be orphaned from your intended
solution. Changes to the web config, once in production, should be
treated as a bug fix or enhancement that required replacement of
binaries.

Example

In your web.config | appsettings section, create a key pair

<Add key="ReportExportRoot" Value = "\\192.168.2.106\syn2sql$\PDF_" />
for more information on appsettings see:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpgenref/html/gngrfappsettingselement.htm

in your application's global.asax on Application_OnStart
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vbcon/html/vbconPageApplicationContext.htm
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpcontheglobalasaxfile.htm

sub application_onstart()
Dim ReportExportRoot as string
ReportExportRoot =
System.Configuration.ConfigurationSettings.AppSett ings("ReportExportRoot")
Application.Lock
Application("ReportExportRoot") = ReportExportRoot
Application.Unlock
end sub

in you application's global.asax on Session_OnStart
sub Session_Onstart()
Dim ReportExportRoot as string
Application.Lock
ReportExportRoot = ctype(Application("ReportExportRoot"),string)
Application.Unlock
Session.item("ReportExportRoot") = ReportExportRoot
end sub

"Alison Givens" <in**@cross-it.nl> wrote in message
news:OT**************@TK2MSFTNGP11.phx.gbl...
I used the code as you suggested, but again I get blue underlines.
First with every GetSessionValue,it has a blue underline:
Name GetSessionValue is not declared

and the other blue underline is GetExportRoot
myExportFile = System.IO.Path.Combine(GetExportRoot,
String.Format("PDF_{0}.pdf", myExportFile))
Says:Argument not specified for parameter 'FromApplication' of
'Private Function GetExportRoot(FromApplication As Boolean) As String'.

I pasted the code again for your convenience.

Private Enum FileNameFormats
SessionID = 0
GUIDDashes = 1
GUIDNoDashes = 2
End Enum
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
Dim myReport As RapportAIRCOStoringen
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions

Try

Try
PrepareReport(myReport)
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to prepare
report.", ex)
Throw exc
End Try

Try
'exporteren to pdf
myExportOptions =
GetExportOptions(FileNameFormats.GUIDNoDashes, CType(myReport,
CrystalDecisions.CrystalReports.Engine.ReportDocum ent).ExportOptions)
myReport.Export()

Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to export
report.", ex)
Throw exc
End Try

crViewer.ReportSource = myReport

Session("exportbestand") =
CType(myExportOptions.DestinationOptions,
CrystalDecisions.Shared.DiskFileDestinationOptions ).DiskFileName

Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try


End Sub

#End Region

#Region "Page Implementation"

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload
Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

System.IO.File.Delete(myExportFile)
End Sub

#End Region

#Region "Report Setup"

Private Sub PrepareReport(ByVal myReport As
CrystalDecisions.CrystalReports.Engine.ReportDocum ent)

Dim paramFields As ParameterFields
Dim paramField As ParameterField

Const SessionExecption As String = "Unable to read session
objects."

Try

paramFields = New ParameterFields
Try
paramField = CreateParameter("FiliaalKeuze")

paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("DiscreteValue1")))

paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("DiscreteValue1")))

Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption,
ex)
Throw exc
End Try

myReport.SetParameterValue("FiliaalKeuze", paramField)

Try
'Todo wrap in try
paramField = CreateParameter("Periode")

paramField.CurrentValues.Add(CreateParameterRangeV alue(GetSessionValue("BeginPeriode"),
GetSessionValue("EindPeriode")))
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption,
ex)
Throw exc
End Try

myReport.SetParameterValue("Periode", paramField)

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to set
paramatervalue.", ex)
Throw exc

End Try
End Sub

Private Function CreateParameter(ByVal ParameterName As String) As
ParameterField
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParameterName

Return paramField

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object)
As ParameterDiscreteValue

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As
Object, ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function

#End Region

#Region "Report Export"

Private Function GetExportOptions(ByVal UniqueFormat As
FileNameFormats, ByVal ExportOptions As
CrystalDecisions.Shared.ExportOptions) As
CrystalDecisions.Shared.ExportOptions

Dim myExportFile As String
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
Dim myDiskFileDestinationOptions As
CrystalDecisions.Shared.DiskFileDestinationOptions

Try

Select Case UniqueFormat
Case FileNameFormats.SessionID
myExportFile = Session.SessionID.ToString
Case FileNameFormats.GUIDDashes
myExportFile = System.Guid.NewGuid.ToString("D")
Case FileNameFormats.GUIDNoDashes
myExportFile = System.Guid.NewGuid.ToString("N")
End Select

myExportFile = System.IO.Path.Combine(GetExportRoot,
String.Format("PDF_{0}.pdf", myExportFile))

myDiskFileDestinationOptions = New
CrystalDecisions.Shared.DiskFileDestinationOptions
myDiskFileDestinationOptions.DiskFileName = myExportFile

myExportOptions = ExportOptions

With myExportOptions
.DestinationOptions = myDiskFileDestinationOptions
.ExportDestinationType = .ExportDestinationType.DiskFile
.ExportFormatType = .ExportFormatType.PortableDocFormat
End With

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to prepare
export options.", ex)
Throw exc

End Try

Return myExportOptions

End Function

Private Function GetExportRoot(ByVal FromApplication As Boolean) As
String

Dim strExportRoot As String

If FromApplication Then
Try
Application.Lock()
strExportRoot = Application("ReportExportRoot")
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to lock Web
Application for read.", ex)
Throw exc
Finally
Application.UnLock()
End Try
Else
strExportRoot = Session("ReportExportRoot")
End If

Return strExportRoot

End Function

#End Region

#Region "Navigation Implementation"

Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"

Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

Response.WriteFile(myExportFile)
Response.Flush()
Response.Close()

System.IO.File.Delete(myExportFile)

End Sub

Private Sub cmdEerste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEerste.Click
crViewer.ShowFirstPage()
End Sub

Private Sub cmdLaatste_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdLaatste.Click
crViewer.ShowLastPage()
End Sub

Private Sub cmdTerug_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdTerug.Click
crViewer.ShowPreviousPage()
End Sub

Private Sub cmdVerder_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdVerder.Click
crViewer.ShowNextPage()
End Sub

Private Sub drpZoom_SelectedIndexChanged(ByVal sender As Object, ByVal
e
As System.EventArgs) Handles drpZoom.SelectedIndexChanged
crViewer.Zoom(drpZoom.SelectedItem.Value)
End Sub

#End Region
End Class


"AMDRIT" <am****@hotmail.com> wrote in message
news:Op**************@TK2MSFTNGP09.phx.gbl...
Ok, first the isue you were having with the "Blue lines" is:

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue()
--> Retun type is expecting an array of ParameterDiscreteValue

it should be

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue
--> Retun type is expecting an single ParameterDiscreteValue

Second (Mostly because I was bored and also because I am still a
novice), I have altered your code yet again.
Private Enum FileNameFormats
SessionID = 0
GUIDDashes = 1
GUIDNoDashes = 2
End Enum

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()

Dim myReport As RapportAIRCOStoringen
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions

Try

Try
PrepareReport(myReport)
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to prepare report.", ex)
Throw exc
End Try

Try
'exporteren to pdf
myExportOptions = GetExportOptions(FileNameFormats.GUIDNoDashes,
CType(myReport,
CrystalDecisions.CrystalReports.Engine.ReportDocum ent).ExportOptions)
myReport.Export()

Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to export report.", ex)
Throw exc
End Try

crViewer.ReportSource = myReport

Session("exportbestand") =
CType(myExportOptions.DestinationOptions,
CrystalDecisions.Shared.DiskFileDestinationOptions ).DiskFileName

Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try

End Sub

#Region "Page Implementation"

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload
Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

System.IO.File.Delete(myExportFile)
End Sub

#End Region

#Region "Report Setup"

Private Sub PrepareReport(ByVal myReport As
CrystalDecisions.CrystalReports.Engine.ReportDocum ent)

Dim paramFields As ParameterFields
Dim paramField As ParameterField

Const SessionExecption As String = "Unable to read session objects."

Try

paramFields = New ParameterFields
Try
paramField = CreateParameter("FiliaalKeuze")

paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("DiscreteValue1")))

paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("DiscreteValue1")))
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption, ex)
Throw exc
End Try

myReport.SetParameterValue("FiliaalKeuze", paramField)

Try
'Todo wrap in try
paramField = CreateParameter("Periode")

paramField.CurrentValues.Add(CreateParameterRangeV alue(GetSessionValue("BeginPeriode"),
GetSessionValue("EindPeriode")))
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption, ex)
Throw exc
End Try

myReport.SetParameterValue("Periode", paramField)

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to set paramater
value.", ex)
Throw exc

End Try
End Sub

Private Function CreateParameter(ByVal ParameterName As String) As
ParameterField
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParameterName

Return paramField

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object)
As ParameterDiscreteValue()

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

'Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As Object,
ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function

#End Region

#Region "Report Export"

Private Function GetExportOptions(ByVal UniqueFormat As
FileNameFormats, ByVal ExportOptions As
CrystalDecisions.Shared.ExportOptions) As
CrystalDecisions.Shared.ExportOptions

Dim myExportFile As String
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
Dim myDiskFileDestinationOptions As
CrystalDecisions.Shared.DiskFileDestinationOptions

Try

Select Case UniqueFormat
Case FileNameFormats.SessionID
myExportFile = Session.SessionID.ToString
Case FileNameFormats.GUIDDashes
myExportFile = System.Guid.NewGuid.ToString("D")
Case FileNameFormats.GUIDNoDashes
myExportFile = System.Guid.NewGuid.ToString("N")
End Select

myExportFile = System.IO.Path.Combine(GetExportRoot,
String.Format("PDF_{0}.pdf", myExportFile))

myDiskFileDestinationOptions = New
CrystalDecisions.Shared.DiskFileDestinationOptions
myDiskFileDestinationOptions.DiskFileName = myExportFile

myExportOptions = ExportOptions

With myExportOptions
.DestinationOptions = myDiskFileDestinationOptions
.ExportDestinationType = .ExportDestinationType.DiskFile
.ExportFormatType = .ExportFormatType.PortableDocFormat
End With

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to prepare export
options.", ex)
Throw exc

End Try

Return myExportOptions

End Function

Private Function GetExportRoot(ByVal FromApplication As Boolean) As
String

Dim strExportRoot As String

If FromApplication Then
Try
Application.lock()
strExportRoot = Application("ReportExportRoot")
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to lock Web Application
for read.", ex)
Throw exc
Finally
Application.unlock()
End Try
Else
strExportRoot = Session("ReportExportRoot")
End If

Return strExportRoot

End Function

#End Region

#Region "Navigation Implementation"

Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"

Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

Response.WriteFile(myExportFile)
Response.Flush()
Response.Close()

System.IO.File.Delete(myExportFile)

End Sub

Private Sub cmdEerste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEerste.Click
crViewer.ShowFirstPage()
End Sub

Private Sub cmdLaatste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdLaatste.Click
crViewer.ShowLastPage()
End Sub

Private Sub cmdTerug_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdTerug.Click
crViewer.ShowPreviousPage()
End Sub

Private Sub cmdVerder_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdVerder.Click
crViewer.ShowNextPage()
End Sub

Private Sub drpZoom_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles drpZoom.SelectedIndexChanged
crViewer.Zoom(drpZoom.SelectedItem.Value)
End Sub

#End Region
"Alison Givens" <in**@cross-it.nl> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
>> Perhaps you could share your resulting code for comparison? Did you
>> see that I suggested the error in your code was
>>
>> myReport.SetParameterValue("FiliaalKeuze", discreteVal) 'You only
>> call this statement once (Effectively 2344) but you wanted two
>> values.
>
> To get the thing going, it would be enough for me at first to know how
> to call the statement twice, so the other value is forwarded too.
> (btw, these two values will be SessionObjects two, but I did it
> hardcoded for testing)
> Best would be ofcourse that I learn to do it 'clean' of course. I am a
> real newbee at this.
>
> Here is the rest of my code:
>
> Imports CrystalDecisions.CrystalReports.Engine
> Imports CrystalDecisions.CrystalReports.Engine.ReportDocum ent
> Imports CrystalDecisions.Shared
> Imports System.IO
>
>
> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Init
> 'CODEGEN: This method call is required by the Web Form Designer
> 'Do not modify it using the code editor.
> InitializeComponent()
>
>
>
> Dim myReport As RapportAIRCOStoringen
> Dim paramFields As ParameterFields
> Dim paramField As ParameterField
>
> Dim BeginPeriode As String
> Dim EindPeriode As String
>
> 'Todo wrap everything in try
> paramFields = New ParameterFields
>
> Try
> BeginPeriode = Request.QueryString("BeginPeriode")
> EindPeriode = Request.QueryString("EindPeriode")
> Catch ex As Exception
> Dim exCustom As ApplicationException
> exCustom = New ApplicationException("Unable to parse Query
> Paramaters.", ex)
> Throw exCustom
> End Try
>
> 'Todo wrap in try
> paramField = CreateParameter("FiliaalKeuze")
>
> paramField.CurrentValues.Add(CreateParameterDiscre teValue(2044))
>
> paramField.CurrentValues.Add(CreateParameterDiscre teValue(2344))
> myReport.SetParameterValue("FiliaalKeuze", paramField)
>
>
> 'Todo wrap in try
> paramField = CreateParameter("Periode")
>
> paramField.CurrentValues.Add(CreateParameterRangeV alue(BeginPeriode,
> EindPeriode))
> myReport.SetParameterValue("Periode", paramField)
>
>
> crViewer.ReportSource = myReport
>
>
> 'exporteren to pdf
> Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
> Dim myDiskFileDestinationOptions As
> CrystalDecisions.Shared.DiskFileDestinationOptions
> Dim myExportFile As String
>
>
>
> myExportFile = "\\192.168.2.106\syn2sql$\PDF_" &
> Session.SessionID.ToString & ".pdf"
> myDiskFileDestinationOptions = New
> CrystalDecisions.Shared.DiskFileDestinationOptions
> myDiskFileDestinationOptions.DiskFileName = myExportFile
> myExportOptions = myReport.ExportOptions
> With myExportOptions
> .DestinationOptions = myDiskFileDestinationOptions
> .ExportDestinationType = .ExportDestinationType.DiskFile
> .ExportFormatType = .ExportFormatType.PortableDocFormat
> End With
>
> Try
> myReport.Export()
> Catch err As Exception
> Response.Write("<BR>")
> Response.Write(err.Message.ToString)
> End Try
>
> Session("exportbestand") = myExportFile
> End Sub
>
> #End Region
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> End Sub
> Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e
> As System.EventArgs) Handles cmdPrint.Click
> Response.ClearContent()
> Response.ClearHeaders()
> Response.ContentType = "application/pdf"
> Dim myExportFile As String =
> CType(Session.Item("exportbestand"), String)
>
> Response.WriteFile(myExportFile)
> Response.Flush()
> Response.Close()
>
> System.IO.File.Delete(myExportFile)
> End Sub
>
> Private Function CreateParameter(ByVal ParameterName As String) As
> ParameterField()
> Dim paramField As ParameterField
>
> paramField = New ParameterField
> paramField.ParameterFieldName = ParameterName
>
> 'Return paramField
>
> End Function
>
> Private Function CreateParameterDiscreteValue(ByVal Value As
> Object) As ParameterDiscreteValue()
>
> Dim paramDiscreteValue As ParameterDiscreteValue
> paramDiscreteValue = New ParameterDiscreteValue
> paramDiscreteValue = Value
>
> 'Return paramDiscreteValue
>
> End Function
>
> Private Function CreateParameterRangeValue(ByVal StartRange As
> Object, ByVal EndRange As Object) As ParameterRangeValue
> Dim paramRangeValue As ParameterRangeValue
>
> paramRangeValue = New ParameterRangeValue
>
> paramRangeValue.StartValue = StartRange
> paramRangeValue.EndValue = EndRange
>
> Return paramRangeValue
> End Function
>
>
> Private Sub cmdEerste_Click(ByVal sender As System.Object, ByVal e
> As System.EventArgs) Handles cmdEerste.Click
> crViewer.ShowFirstPage()
> End Sub
>
> Private Sub cmdLaatste_Click(ByVal sender As System.Object, ByVal e
> As System.EventArgs) Handles cmdLaatste.Click
> crViewer.ShowLastPage()
> End Sub
>
> Private Sub cmdTerug_Click(ByVal sender As System.Object, ByVal e
> As System.EventArgs) Handles cmdTerug.Click
> crViewer.ShowPreviousPage()
> End Sub
>
> Private Sub cmdVerder_Click(ByVal sender As System.Object, ByVal e
> As System.EventArgs) Handles cmdVerder.Click
> crViewer.ShowNextPage()
> End Sub
>
> Private Sub drpZoom_SelectedIndexChanged(ByVal sender As Object,
> ByVal e As System.EventArgs) Handles drpZoom.SelectedIndexChanged
> crViewer.Zoom(drpZoom.SelectedItem.Value)
> End Sub
> Private Sub Page_Unload(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles MyBase.Unload
> Dim myExportFile As String =
> CType(Session.Item("exportbestand"), String)
>
> System.IO.File.Delete(myExportFile)
> End Sub
> End Class
>
>
>
>
>
>
>>
>> "Alison Givens" <in**@cross-it.nl> wrote in message
>> news:ee**************@TK2MSFTNGP09.phx.gbl...
>>> When I use your solution I get blue lines under the text like this
>>>
>>> paramField = CreateParamater("FiliaalKeuze")
>>> The text is:
>>> Value of type '1 dimensional array of
>>> CrystalDecisions.Shared.ParameterField' cannot be converted
>>> to 'Crystal.Decisions.Shared.ParameterField'
>>>
>>> Return paramField
>>> The text is:
>>> Value of type 'CrystalDecisions.Shared.ParameterField' cannot be
>>> converted
>>> to '1 dimensional array of Crystal.Decisions.Shared.ParameterField'
>>>
>>> Same for
>>> paramField = CreateParamater("Periode")
>>> Return paramDiscreteValue
>>>
>>> Any idea what causes this?
>>>
>>> Alison
>>>
>>>
>>> "AMDRIT" <am****@hotmail.com> wrote in message
>>> news:ur*************@TK2MSFTNGP14.phx.gbl...
>>>> Wow, you do all that for Crystal Reports? What is
>>>> RapportAIRCOStoringen?
>>>>
>>>>
>>>> Here is all I do for CR
>>>>
>>>> Dim x As CrystalDecisions.CrystalReports.Engine.ReportDocum ent
>>>>
>>>> x.Load(sReportPath) 'Reports are not embedded resources
>>>> x.SetParameterValue("Paramater1", Paramaters(1)) 'Dynamic
>>>> Paramaters
>>>> x.SetParameterValue("Paramater2", Paramaters(2))
>>>> x.SetDataSource(mydata) 'Strongly Typed Datasets
>>>>
>>>> Me.CrystalReportViewer1.ReportSource = x
>>>> Me.CrystalReportViewer1.PrintReport()
>>>>
>>>>
>>>> 'Now to answer your question about your code, hmm
>>>>
>>>> Ok, first
>>>>
>>>> Never --> Dim x as new object
>>>> 'This is silly, lazy and unprofessional. So if you are in
>>>> high school, keep the course.
>>>>
>>>>
>>>> Instead --> Dim x as object
>>>> Set x = new object
>>>> 'Reserve your space and contract
>>>> 'Then make use of it.
>>>>
>>>> I think this is your problem
>>>>
>>>> myReport.SetParameterValue("FiliaalKeuze", discreteVal)
>>>>
>>>> Why are you setting the crView paramaters and the myReport
>>>> paramaters?
>>>> -->crViewer.ParameterFieldInfo = paramFields
>>>> -->myReport.SetParameterValue("Periode", rangeVal)
>>>>
>>>> I think that myReport is the only think that needs to be set
>>>>
>>>>
>>>> I had to spent time reading your code to understand what you were
>>>> doing.
>>>>
>>>> Here is an attempt to clean it up.
>>>>
>>>> Private Sub TestIT()
>>>>
>>>> Dim myReport As RapportAIRCOStoringen
>>>> Dim paramFields As ParameterFields
>>>> Dim paramField As ParameterField
>>>>
>>>> Dim BeginPeriode As String
>>>> Dim EindPeriode As String
>>>>
>>>> 'Todo wrap everything in try
>>>> paramFields = New ParameterFields
>>>>
>>>> Try
>>>> BeginPeriode = Request.QueryString("BeginPeriode")
>>>> EindPeriode = Request.QueryString("EindPeriode")
>>>> Catch ex As Exception
>>>> Dim exCustom As ApplicationException
>>>> exCustom = New ApplicationException("Unable to parse Query
>>>> Paramaters.", ex)
>>>> Throw exCustom
>>>> End Try
>>>>
>>>> 'Todo wrap in try
>>>> paramField = CreateParamater("FiliaalKeuze")
>>>> paramField.CurrentValues.Add(CreateParameterDiscre teValue(2044))
>>>> paramField.CurrentValues.Add(CreateParameterDiscre teValue(2344))
>>>> myReport.SetParameterValue("FiliaalKeuze", paramField)
>>>> 'paramFields.Add(paramField) --> Not needed
>>>>
>>>> 'Todo wrap in try
>>>> paramField = CreateParamater("Periode")
>>>>
>>>> paramField.CurrentValues.Add(CreateParameterRangeV alue(BeginPeriode,
>>>> EindPeriode))
>>>> myReport.SetParameterValue("Periode", paramField)
>>>> 'paramFields.Add(paramField)--> Not needed
>>>>
>>>> 'Todo wrap in try, i don't think you need this
>>>> 'myReport.SetParameterValue("Periode", rangeVal)
>>>> 'myReport.SetParameterValue("FiliaalKeuze", discreteVal)
>>>>
>>>> 'Todo, determine if we need this step; I don't think you do
>>>> 'crViewer.ParameterFieldInfo = paramFields
>>>>
>>>> crViewer.ReportSource = myReport
>>>>
>>>> End Sub
>>>>
>>>> Private Function CreateParamater(ByVal ParamaterName As String) As
>>>> ParameterField
>>>> Dim paramField As ParameterField
>>>>
>>>> paramField = New ParameterField
>>>> paramField.ParameterFieldName = ParamaterName
>>>>
>>>> Return paramField
>>>>
>>>> End Function
>>>>
>>>> Private Function CreateParameterDiscreteValue(ByVal Value As
>>>> Object) As ParameterDiscreteValue
>>>>
>>>> Dim paramDiscreteValue As ParameterDiscreteValue
>>>> paramDiscreteValue = New ParameterDiscreteValue
>>>> paramDiscreteValue = Value
>>>>
>>>> Return paramDiscreteValue
>>>>
>>>> End Function
>>>>
>>>> Private Function CreateParameterRangeValue(ByVal StartRange As
>>>> Object, ByVal EndRange As Object) As ParameterRangeValue
>>>> Dim paramRangeValue As ParameterRangeValue
>>>>
>>>> paramRangeValue = New ParameterRangeValue
>>>>
>>>> paramRangeValue.StartValue = StartRange
>>>> paramRangeValue.EndValue = EndRange
>>>>
>>>> Return paramRangeValue
>>>> End Function
>>>>
>>>> "Alison Givens" <in**@cross-it.nl> wrote in message
>>>> news:eW*************@TK2MSFTNGP11.phx.gbl...
>>>>> ...... that nobody knows the answer.
>>>>> I can't imagine that I am the only one that uses parameters in CR.
>>>>>
>>>>> So, my question again:
>>>>>
>>>>> I have the following problem.
>>>>> (VB.NET 2003 with CR)
>>>>>
>>>>> I have a report with a multiple-value discrete value and a
>>>>> rangevalue.
>>>>> The report shows fine in the viewer, but when I hit the export to
>>>>> pdf
>>>>> button, it only uses one of two discrete values.
>>>>>
>>>>> This is the code:
>>>>> Dim BeginPeriode As String
>>>>> Dim EindPeriode As String
>>>>>
>>>>> BeginPeriode = Request.QueryString("BeginPeriode")
>>>>> EindPeriode = Request.QueryString("EindPeriode")
>>>>>
>>>>> Dim myReport As New RapportAIRCOStoringen
>>>>>
>>>>> Dim paramFields As New ParameterFields
>>>>> Dim paramField As New ParameterField
>>>>> Dim discreteVal As New ParameterDiscreteValue
>>>>> Dim rangeVal As New ParameterRangeValue
>>>>>
>>>>> paramField.ParameterFieldName = "FiliaalKeuze"
>>>>> discreteVal.Value = "2044"
>>>>> paramField.CurrentValues.Add(discreteVal)
>>>>>
>>>>> discreteVal = New ParameterDiscreteValue
>>>>> discreteVal.Value = "2344"
>>>>> paramField.CurrentValues.Add(discreteVal)
>>>>>
>>>>> paramFields.Add(paramField)
>>>>>
>>>>> paramField = New ParameterField
>>>>>
>>>>> paramField.ParameterFieldName = "Periode"
>>>>>
>>>>> rangeVal.StartValue = BeginPeriode
>>>>> rangeVal.EndValue = EindPeriode
>>>>> paramField.CurrentValues.Add(rangeVal)
>>>>>
>>>>> paramFields.Add(paramField)
>>>>>
>>>>> crViewer.ParameterFieldInfo = paramFields
>>>>> myReport.SetParameterValue("Periode", rangeVal)
>>>>> myReport.SetParameterValue("FiliaalKeuze", discreteVal)
>>>>> crViewer.ReportSource = myReport
>>>>>
>>>>> As you can see I use myReport.SetParameterValue to feed the pdf.
>>>>> It goes wrong with the discrete value. It only sees the second
>>>>> value I
>>>>> entered and not the first.
>>>>> How can I get this going?
>>>>>
>>>>>
>>>>> Kind regards,
>>>>> Alison
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>



Feb 22 '06 #10
Yepper, the web.config is case sensitive.
That solves that problem.
Next problem:
When I give in the parameters and go to the form that holds the report I get
this:

Value cannot be null. Parameter name: path
Description: An unhandled exception occurred during the execution of the
current web request.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: path

Source Error:
Line 84: Dim myExportFile As String =
CType(Session.Item("exportbestand"), String)
Line 85:
Line 86: System.IO.File.Delete(myExportFile)
Line 87: End Sub
Line 88:

I commented it, so I could at least try to go further.
Then when the form with the report loads, I get:
Unable to prepare report.

This comes out of this error handeling:
Try
PrepareReport(myReport)
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to prepare report.", ex)
Throw exc
End Try

To be accurate I will put the entire current code here:
Private Enum FileNameFormats
SessionID = 0
GUIDDashes = 1
GUIDNoDashes = 2
End Enum

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
Dim myReport As RapportAIRCOStoringen
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions

Try

Try
PrepareReport(myReport)
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to prepare
report.", ex)
Throw exc
End Try

Try
'exporteren to pdf
myExportOptions =
GetExportOptions(FileNameFormats.GUIDNoDashes, CType(myReport,
CrystalDecisions.CrystalReports.Engine.ReportDocum ent).ExportOptions)
myReport.Export()

Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to export report.",
ex)
Throw exc
End Try

crViewer.ReportSource = myReport

Session("exportbestand") =
CType(myExportOptions.DestinationOptions,
CrystalDecisions.Shared.DiskFileDestinationOptions ).DiskFileName

Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try


End Sub

#End Region

#Region "Page Implementation"

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload
'Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

'System.IO.File.Delete(myExportFile)
End Sub

#End Region

#Region "Report Setup"

Private Sub PrepareReport(ByVal myReport As
CrystalDecisions.CrystalReports.Engine.ReportDocum ent)

Dim paramFields As ParameterFields
Dim paramField As ParameterField

Const SessionExecption As String = "Unable to read session objects."

Try

paramFields = New ParameterFields
Try
paramField = CreateParameter("FiliaalKeuze")
paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("Filiaal")))
'paramField.CurrentValues.Add(CreateParameterDiscr eteValue(GetSessionValue("DiscreteValue2")))
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException(SessionExecption, ex)
Throw exc
End Try

myReport.SetParameterValue("FiliaalKeuze", paramField)

Try
'Todo wrap in try
paramField = CreateParameter("Periode")
paramField.CurrentValues.Add(CreateParameterRangeV alue(GetSessionValue("BeginPeriode"),
GetSessionValue("EindPeriode")))
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption, ex)
Throw exc
End Try

myReport.SetParameterValue("Periode", paramField)

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to set
paramatervalue.", ex)
Throw exc

End Try
End Sub

Private Function CreateParameter(ByVal ParameterName As String) As
ParameterField
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParameterName

Return paramField

End Function
Private Function GetSessionValue(ByVal KeyName As String) As Object
Try
Return Session.Item(KeyName)
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException(String.Format("Unable to read
value from session:{0}", KeyName), ex)
Throw exc
End Try

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As Object,
ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function

#End Region

#Region "Report Export"

Private Function GetExportOptions(ByVal UniqueFormat As FileNameFormats,
ByVal ExportOptions As CrystalDecisions.Shared.ExportOptions) As
CrystalDecisions.Shared.ExportOptions

Dim myExportFile As String
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
Dim myDiskFileDestinationOptions As
CrystalDecisions.Shared.DiskFileDestinationOptions

Try

Select Case UniqueFormat
Case FileNameFormats.SessionID
myExportFile = Session.SessionID.ToString
Case FileNameFormats.GUIDDashes
myExportFile = System.Guid.NewGuid.ToString("D")
Case FileNameFormats.GUIDNoDashes
myExportFile = System.Guid.NewGuid.ToString("N")
End Select

myExportFile = System.IO.Path.Combine(GetExportRoot(True),
String.Format("PDF_{0}.pdf", myExportFile))
myDiskFileDestinationOptions = New
CrystalDecisions.Shared.DiskFileDestinationOptions
myDiskFileDestinationOptions.DiskFileName = myExportFile

myExportOptions = ExportOptions

With myExportOptions
.DestinationOptions = myDiskFileDestinationOptions
.ExportDestinationType = .ExportDestinationType.DiskFile
.ExportFormatType = .ExportFormatType.PortableDocFormat
End With

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to prepare export
options.", ex)
Throw exc

End Try

Return myExportOptions

End Function

Private Function GetExportRoot(ByVal FromApplication As Boolean) As
String

Dim strExportRoot As String

If FromApplication Then
Try
Application.Lock()
strExportRoot = Application("ReportExportRoot")
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to lock Web
Application for read.", ex)
Throw exc
Finally
Application.UnLock()
End Try
Else
strExportRoot = Session("ReportExportRoot")
End If

Return strExportRoot

End Function

#End Region

#Region "Navigation Implementation"

Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"

Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

Response.WriteFile(myExportFile)
Response.Flush()
Response.Close()

System.IO.File.Delete(myExportFile)

End Sub

Private Sub cmdEerste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEerste.Click
crViewer.ShowFirstPage()
End Sub

Private Sub cmdLaatste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdLaatste.Click
crViewer.ShowLastPage()
End Sub

Private Sub cmdTerug_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdTerug.Click
crViewer.ShowPreviousPage()
End Sub

Private Sub cmdVerder_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdVerder.Click
crViewer.ShowNextPage()
End Sub

Private Sub drpZoom_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles drpZoom.SelectedIndexChanged
crViewer.Zoom(drpZoom.SelectedItem.Value)
End Sub

#End Region
Feb 23 '06 #11
I challenge you to consider what is going on and ask why would that type of
exception occur.

It appears that in your Page_Unload() you are attempting to do clean up.

Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload
Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)
System.IO.File.Delete(myExportFile)
End Sub

The problem is that the Session item "exportbestand" appears to be
string.empty. Perhaps, the value was never properly set.

The only place I see that you are setting the Session item is in page_init()

Session("exportbestand") = CType _
(myExportOptions.DestinationOptions,
CrystalDecisions.Shared.DiskFileDestinationOptions ).DiskFileName

You should test to see if DiskFileName has value, and if not, then work
backwards to where it is set to determine if a value is being set there.
Next, consider why the page_unload is firing without first displaying your
report.

try something like this in you error handling routine:

Try
PrepareReport(myReport)
Catch ex As Exception
dim innerEx as Exception, sb as system.text.stringbuilder
sb = new system.text.stringbuilder

sb.append(ex.tostring)

innerEx = ex.innerexception

do while not innerEx is nothing
sb.append(vbcrlf)
sb.append(innerEx.tostring)
innerEx = innerEx.innerexception
loop

response.write(sb.tostring)
response.end

'exc = New ApplicationException("Unable to prepare report.", ex)
'Throw exc
End Try
"Alison Givens" <in**@cross-it.nl> wrote in message
news:O0**************@TK2MSFTNGP15.phx.gbl...
Yepper, the web.config is case sensitive.
That solves that problem.
Next problem:
When I give in the parameters and go to the form that holds the report I
get this:

Value cannot be null. Parameter name: path
Description: An unhandled exception occurred during the execution of the
current web request.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: path

Source Error:
Line 84: Dim myExportFile As String =
CType(Session.Item("exportbestand"), String)
Line 85:
Line 86: System.IO.File.Delete(myExportFile)
Line 87: End Sub
Line 88:

I commented it, so I could at least try to go further.
Then when the form with the report loads, I get:
Unable to prepare report.

This comes out of this error handeling:
Try
PrepareReport(myReport)
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to prepare report.", ex)
Throw exc
End Try

To be accurate I will put the entire current code here:
Private Enum FileNameFormats
SessionID = 0
GUIDDashes = 1
GUIDNoDashes = 2
End Enum

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
Dim myReport As RapportAIRCOStoringen
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions

Try

Try
PrepareReport(myReport)
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to prepare
report.", ex)
Throw exc
End Try

Try
'exporteren to pdf
myExportOptions =
GetExportOptions(FileNameFormats.GUIDNoDashes, CType(myReport,
CrystalDecisions.CrystalReports.Engine.ReportDocum ent).ExportOptions)
myReport.Export()

Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to export report.",
ex)
Throw exc
End Try

crViewer.ReportSource = myReport

Session("exportbestand") =
CType(myExportOptions.DestinationOptions,
CrystalDecisions.Shared.DiskFileDestinationOptions ).DiskFileName

Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try


End Sub

#End Region

#Region "Page Implementation"

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload
'Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

'System.IO.File.Delete(myExportFile)
End Sub

#End Region

#Region "Report Setup"

Private Sub PrepareReport(ByVal myReport As
CrystalDecisions.CrystalReports.Engine.ReportDocum ent)

Dim paramFields As ParameterFields
Dim paramField As ParameterField

Const SessionExecption As String = "Unable to read session
objects."

Try

paramFields = New ParameterFields
Try
paramField = CreateParameter("FiliaalKeuze")

paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("Filiaal")))

'paramField.CurrentValues.Add(CreateParameterDiscr eteValue(GetSessionValue("DiscreteValue2")))
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException(SessionExecption, ex)
Throw exc
End Try

myReport.SetParameterValue("FiliaalKeuze", paramField)

Try
'Todo wrap in try
paramField = CreateParameter("Periode")

paramField.CurrentValues.Add(CreateParameterRangeV alue(GetSessionValue("BeginPeriode"),
GetSessionValue("EindPeriode")))
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption, ex)
Throw exc
End Try

myReport.SetParameterValue("Periode", paramField)

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to set
paramatervalue.", ex)
Throw exc

End Try
End Sub

Private Function CreateParameter(ByVal ParameterName As String) As
ParameterField
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParameterName

Return paramField

End Function
Private Function GetSessionValue(ByVal KeyName As String) As Object
Try
Return Session.Item(KeyName)
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException(String.Format("Unable to read
value from session:{0}", KeyName), ex)
Throw exc
End Try

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As Object,
ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function

#End Region

#Region "Report Export"

Private Function GetExportOptions(ByVal UniqueFormat As
FileNameFormats, ByVal ExportOptions As
CrystalDecisions.Shared.ExportOptions) As
CrystalDecisions.Shared.ExportOptions

Dim myExportFile As String
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
Dim myDiskFileDestinationOptions As
CrystalDecisions.Shared.DiskFileDestinationOptions

Try

Select Case UniqueFormat
Case FileNameFormats.SessionID
myExportFile = Session.SessionID.ToString
Case FileNameFormats.GUIDDashes
myExportFile = System.Guid.NewGuid.ToString("D")
Case FileNameFormats.GUIDNoDashes
myExportFile = System.Guid.NewGuid.ToString("N")
End Select

myExportFile = System.IO.Path.Combine(GetExportRoot(True),
String.Format("PDF_{0}.pdf", myExportFile))
myDiskFileDestinationOptions = New
CrystalDecisions.Shared.DiskFileDestinationOptions
myDiskFileDestinationOptions.DiskFileName = myExportFile

myExportOptions = ExportOptions

With myExportOptions
.DestinationOptions = myDiskFileDestinationOptions
.ExportDestinationType = .ExportDestinationType.DiskFile
.ExportFormatType = .ExportFormatType.PortableDocFormat
End With

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to prepare export
options.", ex)
Throw exc

End Try

Return myExportOptions

End Function

Private Function GetExportRoot(ByVal FromApplication As Boolean) As
String

Dim strExportRoot As String

If FromApplication Then
Try
Application.Lock()
strExportRoot = Application("ReportExportRoot")
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to lock Web
Application for read.", ex)
Throw exc
Finally
Application.UnLock()
End Try
Else
strExportRoot = Session("ReportExportRoot")
End If

Return strExportRoot

End Function

#End Region

#Region "Navigation Implementation"

Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"

Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

Response.WriteFile(myExportFile)
Response.Flush()
Response.Close()

System.IO.File.Delete(myExportFile)

End Sub

Private Sub cmdEerste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEerste.Click
crViewer.ShowFirstPage()
End Sub

Private Sub cmdLaatste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdLaatste.Click
crViewer.ShowLastPage()
End Sub

Private Sub cmdTerug_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdTerug.Click
crViewer.ShowPreviousPage()
End Sub

Private Sub cmdVerder_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdVerder.Click
crViewer.ShowNextPage()
End Sub

Private Sub drpZoom_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles drpZoom.SelectedIndexChanged
crViewer.Zoom(drpZoom.SelectedItem.Value)
End Sub

#End Region

Feb 23 '06 #12
I used the error code as suggested in the PrepareReport.
This is the result:

System.ApplicationException: Unable to set paramatervalue. --->
System.ApplicationException: Unable to read session objects. --->
System.InvalidCastException: Specified cast is not valid. at
rapportage.ProductiviteitsLijst.CreateParameterDis creteValue(Object Value)
in \\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.asp x.vb:line 177 at
rapportage.ProductiviteitsLijst.PrepareReport(Repo rtDocument myReport) in
\\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.asp x.vb:line 116 --- End
of inner exception stack trace --- at
rapportage.ProductiviteitsLijst.PrepareReport(Repo rtDocument myReport) in
\\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.asp x.vb:line 121 --- End
of inner exception stack trace --- at
rapportage.ProductiviteitsLijst.PrepareReport(Repo rtDocument myReport) in
\\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.asp x.vb:line 142 at
rapportage.ProductiviteitsLijst.Page_Init(Object sender, EventArgs e) in
\\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.asp x.vb:line 43
System.ApplicationException: Unable to read session objects. --->
System.InvalidCastException: Specified cast is not valid. at
rapportage.ProductiviteitsLijst.CreateParameterDis creteValue(Object Value)
in \\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.asp x.vb:line 177 at
rapportage.ProductiviteitsLijst.PrepareReport(Repo rtDocument myReport) in
\\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.asp x.vb:line 116 --- End
of inner exception stack trace --- at
rapportage.ProductiviteitsLijst.PrepareReport(Repo rtDocument myReport) in
\\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.asp x.vb:line 121
System.InvalidCastException: Specified cast is not valid. at
rapportage.ProductiviteitsLijst.CreateParameterDis creteValue(Object Value)
in \\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.asp x.vb:line 177 at
rapportage.ProductiviteitsLijst.PrepareReport(Repo rtDocument myReport) in
\\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.asp x.vb:line 116
Thread was being aborted.






"AMDRIT" <am****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I challenge you to consider what is going on and ask why would that type of
exception occur.

It appears that in your Page_Unload() you are attempting to do clean up.

Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload
Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)
System.IO.File.Delete(myExportFile)
End Sub

The problem is that the Session item "exportbestand" appears to be
string.empty. Perhaps, the value was never properly set.

The only place I see that you are setting the Session item is in
page_init()

Session("exportbestand") = CType _
(myExportOptions.DestinationOptions,
CrystalDecisions.Shared.DiskFileDestinationOptions ).DiskFileName

You should test to see if DiskFileName has value, and if not, then work
backwards to where it is set to determine if a value is being set there.
Next, consider why the page_unload is firing without first displaying your
report.

try something like this in you error handling routine:

Try
PrepareReport(myReport)
Catch ex As Exception
dim innerEx as Exception, sb as system.text.stringbuilder
sb = new system.text.stringbuilder

sb.append(ex.tostring)

innerEx = ex.innerexception

do while not innerEx is nothing
sb.append(vbcrlf)
sb.append(innerEx.tostring)
innerEx = innerEx.innerexception
loop

response.write(sb.tostring)
response.end

'exc = New ApplicationException("Unable to prepare report.", ex)
'Throw exc
End Try
"Alison Givens" <in**@cross-it.nl> wrote in message
news:O0**************@TK2MSFTNGP15.phx.gbl...
Yepper, the web.config is case sensitive.
That solves that problem.
Next problem:
When I give in the parameters and go to the form that holds the report I
get this:

Value cannot be null. Parameter name: path
Description: An unhandled exception occurred during the execution of the
current web request.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: path

Source Error:
Line 84: Dim myExportFile As String =
CType(Session.Item("exportbestand"), String)
Line 85:
Line 86: System.IO.File.Delete(myExportFile)
Line 87: End Sub
Line 88:

I commented it, so I could at least try to go further.
Then when the form with the report loads, I get:
Unable to prepare report.

This comes out of this error handeling:
Try
PrepareReport(myReport)
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to prepare report.", ex)
Throw exc
End Try

To be accurate I will put the entire current code here:
Private Enum FileNameFormats
SessionID = 0
GUIDDashes = 1
GUIDNoDashes = 2
End Enum

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
Dim myReport As RapportAIRCOStoringen
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions

Try

Try
PrepareReport(myReport)
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to prepare
report.", ex)
Throw exc
End Try

Try
'exporteren to pdf
myExportOptions =
GetExportOptions(FileNameFormats.GUIDNoDashes, CType(myReport,
CrystalDecisions.CrystalReports.Engine.ReportDocum ent).ExportOptions)
myReport.Export()

Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to export report.",
ex)
Throw exc
End Try

crViewer.ReportSource = myReport

Session("exportbestand") =
CType(myExportOptions.DestinationOptions,
CrystalDecisions.Shared.DiskFileDestinationOptions ).DiskFileName

Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try


End Sub

#End Region

#Region "Page Implementation"

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload
'Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

'System.IO.File.Delete(myExportFile)
End Sub

#End Region

#Region "Report Setup"

Private Sub PrepareReport(ByVal myReport As
CrystalDecisions.CrystalReports.Engine.ReportDocum ent)

Dim paramFields As ParameterFields
Dim paramField As ParameterField

Const SessionExecption As String = "Unable to read session
objects."

Try

paramFields = New ParameterFields
Try
paramField = CreateParameter("FiliaalKeuze")

paramField.CurrentValues.Add(CreateParameterDiscre teValue(GetSessionValue("Filiaal")))

'paramField.CurrentValues.Add(CreateParameterDiscr eteValue(GetSessionValue("DiscreteValue2")))
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException(SessionExecption, ex)
Throw exc
End Try

myReport.SetParameterValue("FiliaalKeuze", paramField)

Try
'Todo wrap in try
paramField = CreateParameter("Periode")

paramField.CurrentValues.Add(CreateParameterRangeV alue(GetSessionValue("BeginPeriode"),
GetSessionValue("EindPeriode")))
Catch ex As Exception
Dim exc As System.ApplicationException
exc = New System.ApplicationException(SessionExecption,
ex)
Throw exc
End Try

myReport.SetParameterValue("Periode", paramField)

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to set
paramatervalue.", ex)
Throw exc

End Try
End Sub

Private Function CreateParameter(ByVal ParameterName As String) As
ParameterField
Dim paramField As ParameterField

paramField = New ParameterField
paramField.ParameterFieldName = ParameterName

Return paramField

End Function
Private Function GetSessionValue(ByVal KeyName As String) As Object
Try
Return Session.Item(KeyName)
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException(String.Format("Unable to read
value from session:{0}", KeyName), ex)
Throw exc
End Try

End Function

Private Function CreateParameterDiscreteValue(ByVal Value As Object)
As ParameterDiscreteValue

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

Return paramDiscreteValue

End Function

Private Function CreateParameterRangeValue(ByVal StartRange As Object,
ByVal EndRange As Object) As ParameterRangeValue
Dim paramRangeValue As ParameterRangeValue

paramRangeValue = New ParameterRangeValue

paramRangeValue.StartValue = StartRange
paramRangeValue.EndValue = EndRange

Return paramRangeValue
End Function

#End Region

#Region "Report Export"

Private Function GetExportOptions(ByVal UniqueFormat As
FileNameFormats, ByVal ExportOptions As
CrystalDecisions.Shared.ExportOptions) As
CrystalDecisions.Shared.ExportOptions

Dim myExportFile As String
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
Dim myDiskFileDestinationOptions As
CrystalDecisions.Shared.DiskFileDestinationOptions

Try

Select Case UniqueFormat
Case FileNameFormats.SessionID
myExportFile = Session.SessionID.ToString
Case FileNameFormats.GUIDDashes
myExportFile = System.Guid.NewGuid.ToString("D")
Case FileNameFormats.GUIDNoDashes
myExportFile = System.Guid.NewGuid.ToString("N")
End Select

myExportFile = System.IO.Path.Combine(GetExportRoot(True),
String.Format("PDF_{0}.pdf", myExportFile))
myDiskFileDestinationOptions = New
CrystalDecisions.Shared.DiskFileDestinationOptions
myDiskFileDestinationOptions.DiskFileName = myExportFile

myExportOptions = ExportOptions

With myExportOptions
.DestinationOptions = myDiskFileDestinationOptions
.ExportDestinationType = .ExportDestinationType.DiskFile
.ExportFormatType = .ExportFormatType.PortableDocFormat
End With

Catch ex As Exception

Dim exc As System.ApplicationException
exc = New System.ApplicationException("Unable to prepare
export options.", ex)
Throw exc

End Try

Return myExportOptions

End Function

Private Function GetExportRoot(ByVal FromApplication As Boolean) As
String

Dim strExportRoot As String

If FromApplication Then
Try
Application.Lock()
strExportRoot = Application("ReportExportRoot")
Catch ex As Exception
Dim exc As ApplicationException
exc = New ApplicationException("Unable to lock Web
Application for read.", ex)
Throw exc
Finally
Application.UnLock()
End Try
Else
strExportRoot = Session("ReportExportRoot")
End If

Return strExportRoot

End Function

#End Region

#Region "Navigation Implementation"

Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"

Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

Response.WriteFile(myExportFile)
Response.Flush()
Response.Close()

System.IO.File.Delete(myExportFile)

End Sub

Private Sub cmdEerste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEerste.Click
crViewer.ShowFirstPage()
End Sub

Private Sub cmdLaatste_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdLaatste.Click
crViewer.ShowLastPage()
End Sub

Private Sub cmdTerug_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdTerug.Click
crViewer.ShowPreviousPage()
End Sub

Private Sub cmdVerder_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdVerder.Click
crViewer.ShowNextPage()
End Sub

Private Sub drpZoom_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles drpZoom.SelectedIndexChanged
crViewer.Zoom(drpZoom.SelectedItem.Value)
End Sub

#End Region


Feb 27 '06 #13
Hello Alison,

Take a look at what the exception output is telling you.

System.InvalidCastException: Specified cast is not valid. at
rapportage.ProductiviteitsLijst.CreateParameterDis creteValue(Object Value)

If we take a look at the mechanics of that function, you will see:

-->Define variable <-- set's the contract of the object we want, as long as
we hold a reference to the appropriate library we should be fine with this
line of code

-->Create variable <-- just like frakenstien, bring it to life. It is
possible to screw up here, especially if the New() is expecting input.

-->Assign some value to the Value property <-- Here we can screw up by
assigning a value type to the property that is not convertible to the
desired type. Or, we could simply neglect to specify which property we wish
to modify, in which case we would be trying to change the contract of the
variable.

If you take a closer inspection, you should not that the code does not
attempt to assign a value to the Value() property, rather it attempts to
assign the value to the object itself. So in effect, we made space for a
ParameterDiscreteValue and attempted to change it into a string.

If you turn on Option Strict (easiest way is to type Option Strict On, at
the top of your code pane; before any other text), issues like this will be
revealed before you compile. The downside to doing this is that you will
loose all of your implicit type conversions that VB does for you. That
means:

dim objString as string
objString = 6
(This will produce compiler error, since VB will not try to convert a number
'Integer' into a string.)

Becomes

dim objString as string
objString = 6.ToString
(Please note that all objects have a ToString method, however; not all will
provide the String like number types will. Example: a datatable.tostring
will return something like "system.data.datatable" rather than the data
inside the object.)

or

dim objString as string
objString = ctype(6,string)
(Please note that there are two generic type converters, CType and
DirectCast, look them up as homework, You should get into practice of using
them as a matter of process.)

If you are using C#, instead of ctype you can create the conversion as such:

String objString=String.Empty;
objString = (string)6;
(I don't know what that is called, I just think it is cool. Eitherway, it
solves for Option Strict issues.)
It appears that your problem is here

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue
paramDiscreteValue = Value

Return paramDiscreteValue

End Function

Should be

Private Function CreateParameterDiscreteValue(ByVal Value As Object) As
ParameterDiscreteValue

Dim paramDiscreteValue As ParameterDiscreteValue
paramDiscreteValue = New ParameterDiscreteValue

'--==>Assign Value to the value property, not the object.'<==--
paramDiscreteValue.Value = Value

Return paramDiscreteValue
End Function
Let me know if any of this is not clear.
Feb 27 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Julia Briggs | last post by:
I am struggling to create a PHP function that would take a specified image (JPG, GIF or PNG) from a link, and resize it down to a thumbnail so it will always fit in a 200x250 space. I am hoping...
36
by: rbt | last post by:
Say I have a list that has 3 letters in it: I want to print all the possible 4 digit combinations of those 3 letters: 4^3 = 64 aaaa
20
by: CHIN | last post by:
Hi all.. here s my problem ( maybe some of you saw me on other groups, but i cant find the solution !! ) I have to upload a file to an external site, so, i made a .vbs file , that logins to...
7
by: Andrzej | last post by:
Is it possible to call a function which name is given by a string? Let assume that I created a program which call some functions for example void f1(void), void f2(void), void f3(void). ...
2
by: Bhupesh Naik | last post by:
This is a query regarding my problem to make a spell and grammar check possible in text area of a web page. We have aspx pages which are used to construct letters. The browser based screens...
1
by: AAA | last post by:
hi, I'll explain fastly the program that i'm doing.. the computer asks me to enter the cardinal of a set X ( called "dimX" type integer)where X is a table of one dimension and then to fill it...
25
by: Piotr Nowak | last post by:
Hi, Say i have a server process which listens for some changes in database. When a change occurs i want to refresh my page in browser by notyfinig it. I do not want to refresh my page i.e....
4
by: RSH | last post by:
Okay my math skills aren't waht they used to be... With that being said what Im trying to do is create a matrix that given x number of columns, and y number of possible values i want to generate...
7
by: Robert S. | last post by:
Searching some time now for documents on this but still did not find anything about it: Is it possible to replace the entry screen of MS Office Access 2007 - that one presenting that default...
14
by: bjorklund.emil | last post by:
Hello pythonistas. I'm a newbie to pretty much both programming and Python. I have a task that involves writing a test script for every possible combination of preference settings for a software...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.