
Error in temp file in running crystal report for .net in vb.net
The following is my code behind the form with the crystalreportviewer
on it. Thanks! :
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class frmClientWorkOrderRpt
Inherits System.Windows.Forms.Form
Public strWorkOrdVal As String
Public strEmpName As String
#Region " Windows Form Designer generated code "
Private Sub CrystalReportViewer1_Load(ByVal sender As Object,
ByVal e As System.EventArgs) Handles CrystalReportViewer1.Load
Try
Dim strDataLoc As String
Windows.Forms.Cursor.Current() =
Windows.Forms.Cursors.WaitCursor()
'Find the directory where the data is located.
strDataLoc = ReadXmlConfigFile("config.xml", "data_loc")
'Copy the data file to a new file named WorkOrdSum.xml
Dim Fi As New System.IO.FileInfo(strDataLoc &
"\ClientWorkOrd.xml")
'If the file exists, then delete it.
If Fi.Exists Then
Fi.Delete()
End If
'Create the file with the current information in it.
FileOpen(1, strDataLoc & "\ClientWorkOrd.xml",
OpenMode.Append, OpenAccess.ReadWrite, OpenShare.LockReadWrite)
FileClose(1)
'Insert the data from the ds into this file.
WriteXmlToTempFile(DsTimeEntry, strDataLoc)
'Set the selection formula so it only displays the current
work order.
Dim crReport As New ClientWorkOrd()
Dim crParameterFieldDefinitions As
CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions
Dim crParameterFieldDefinition As
CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition
Dim crParameterValues As New
CrystalDecisions.Shared.ParameterValues()
Dim crParameterDiscreteValue As New
CrystalDecisions.Shared.ParameterDiscreteValue()
'Set String Parameter
'Set discrete value
crParameterDiscreteValue.Value = CStr(strEmpName)
'Access first parameter field definition
crParameterFieldDefinitions =
crReport.DataDefinition.ParameterFields
crParameterFieldDefinition =
crParameterFieldDefinitions.Item("EmpName")
' Add a parameter value
crParameterValues =
crParameterFieldDefinition.CurrentValues
crParameterValues.Add(crParameterDiscreteValue)
' Apply the current value to the parameter definition
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
CrystalReportViewer1.SelectionFormula =
"{WorkOrdSum.work_order_no}='" & strWorkOrdVal & "'"
CrystalReportViewer1.ReportSource = crReport
' crReport.DataDefinition()
Windows.Forms.Cursor.Current() =
Windows.Forms.Cursors.Arrow
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
Private Function AddParameter(ByVal paramName As String, _
ByVal paramValue As String, ByVal paramFields As
CrystalDecisions.Shared.ParameterFields) As
CrystalDecisions.Shared.ParameterFields
Try
Dim paramField As New
CrystalDecisions.Shared.ParameterField()
Dim paramDiscreteValue As New
CrystalDecisions.Shared.ParameterDiscreteValue()
Dim paramValues As New
CrystalDecisions.Shared.ParameterValues()
' Set the name of the parameter to modify.
paramField.ParameterFieldName = paramName
' Set a value to the parameter.
paramDiscreteValue.Value = paramValue
paramValues.Add(paramDiscreteValue)
paramField.CurrentValues = paramValues
' Add the parameter to the ParameterFields collection.
paramFields.Add(paramField)
Return paramFields
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Function
Private Sub WriteXmlToTempFile(ByVal thisDataSet As DataSet, ByVal
strDataLoc As String)
Try
If thisDataSet Is Nothing Then
Return
End If
'thisDataSet.AcceptChanges()
' Create a file name to write to.
Dim filename As String = strDataLoc & "\WorkOrdSum.xml"
' Create the FileStream to write with.
Dim myFileStream As New System.IO.FileStream _
(filename, System.IO.FileMode.Create)
' Create an XmlTextWriter with the fileStream.
Dim myXmlWriter As New System.Xml.XmlTextWriter _
(myFileStream, System.Text.Encoding.Unicode)
' Write to the file with the WriteXml method.
thisDataSet.WriteXml(myXmlWriter)
myXmlWriter.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class
Quote:
> Hi..
> Try post your code here..
> Thanks.
> > I sometimes get an error when running my vb.net application when
> > setting the report source for the report. I get the following error:
> > A first chance exception of type
> > 'CrystalDecisions.CrystalReports.Engine.InternalException' occurred in
> > crystaldecisions.reportsource.dll
> > Additional information: Error in File
> C:\DOCUME~1\azb\LOCALS~1\Temp\temp_24e73784-65ca-47bf-8382-d0839c94525f.rpt:
> > The request could not be submitted for background processing.
> > Any help that anyone could give me on this issue would be greatly
> > appreciated! Thanks!