How is it possible ...

A

Alison Givens

....... 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
 
A

AMDRIT

Wow, you do all that for Crystal Reports? What is RapportAIRCOStoringen?


Here is all I do for CR

Dim x As CrystalDecisions.CrystalReports.Engine.ReportDocument

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(CreateParameterDiscreteValue(2044))
paramField.CurrentValues.Add(CreateParameterDiscreteValue(2344))
myReport.SetParameterValue("FiliaalKeuze", paramField)
'paramFields.Add(paramField) --> Not needed

'Todo wrap in try
paramField = CreateParamater("Periode")
paramField.CurrentValues.Add(CreateParameterRangeValue(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
 
A

Alison Givens

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
 
A

AMDRIT

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.
 
A

Alison Givens

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.ReportDocument
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(CreateParameterDiscreteValue(2044))
paramField.CurrentValues.Add(CreateParameterDiscreteValue(2344))
myReport.SetParameterValue("FiliaalKeuze", paramField)


'Todo wrap in try
paramField = CreateParameter("Periode")
paramField.CurrentValues.Add(CreateParameterRangeValue(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
 
A

AMDRIT

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.ReportDocument).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.ReportDocument)

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(CreateParameterDiscreteValue(GetSessionValue("DiscreteValue1")))
paramField.CurrentValues.Add(CreateParameterDiscreteValue(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(CreateParameterRangeValue(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
 
A

Alison Givens

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.ReportDocument).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.ReportDocument)

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(CreateParameterDiscreteValue(GetSessionValue("DiscreteValue1")))
paramField.CurrentValues.Add(CreateParameterDiscreteValue(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(CreateParameterRangeValue(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
 
A

Alison Givens

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.ReportDocument).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.ReportDocument)

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(CreateParameterDiscreteValue(GetSessionValue("Filiaal")))
'paramField.CurrentValues.Add(CreateParameterDiscreteValue(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(CreateParameterRangeValue(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
 
A

AMDRIT

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
 
A

Alison Givens

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.CreateParameterDiscreteValue(Object Value)
in \\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.aspx.vb:line 177 at
rapportage.ProductiviteitsLijst.PrepareReport(ReportDocument myReport) in
\\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.aspx.vb:line 116 --- End
of inner exception stack trace --- at
rapportage.ProductiviteitsLijst.PrepareReport(ReportDocument myReport) in
\\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.aspx.vb:line 121 --- End
of inner exception stack trace --- at
rapportage.ProductiviteitsLijst.PrepareReport(ReportDocument myReport) in
\\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.aspx.vb:line 142 at
rapportage.ProductiviteitsLijst.Page_Init(Object sender, EventArgs e) in
\\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.aspx.vb:line 43
System.ApplicationException: Unable to read session objects. --->
System.InvalidCastException: Specified cast is not valid. at
rapportage.ProductiviteitsLijst.CreateParameterDiscreteValue(Object Value)
in \\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.aspx.vb:line 177 at
rapportage.ProductiviteitsLijst.PrepareReport(ReportDocument myReport) in
\\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.aspx.vb:line 116 --- End
of inner exception stack trace --- at
rapportage.ProductiviteitsLijst.PrepareReport(ReportDocument myReport) in
\\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.aspx.vb:line 121
System.InvalidCastException: Specified cast is not valid. at
rapportage.ProductiviteitsLijst.CreateParameterDiscreteValue(Object Value)
in \\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.aspx.vb:line 177 at
rapportage.ProductiviteitsLijst.PrepareReport(ReportDocument myReport) in
\\KP-COBRA\wwwroot$\rapportage\ProductiviteitsLijst.aspx.vb:line 116
Thread was being aborted.
 
A

AMDRIT

Hello Alison,

Take a look at what the exception output is telling you.

System.InvalidCastException: Specified cast is not valid. at
rapportage.ProductiviteitsLijst.CreateParameterDiscreteValue(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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top