Reputation: 11
Here's my code for crystal reports:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim SqlConn As New SqlConnection("Data Source=classified; Database= classified; User Id= classified; password= classified")
Dim value As String = My.Application.Info.DirectoryPath
Dim path As String = "H:\Auto Dealer Project\Public"
' Determine whether the directory exists.
If Directory.Exists(path) Then
Console.WriteLine("That specified path exists already.")
End If
Dim dirpath As DirectoryInfo = Directory.CreateDirectory(path)
Console.WriteLine("Temp directory was created:", Directory.GetCreationTime(path))
' To load the crystal report in to the report document
cryRpt.Load(My.Application.Info.DirectoryPath & "\CrystalExport.pdf")
MessageBox.Show(My.Application.Info.DirectoryPath, path)
' to update the cystal report
cryRpt.Refresh()
Try
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
CrDiskFileDestinationOptions.DiskFileName = "H:\Auto Dealer Project\Public\CrystalExport.pdf"
CrExportOptions = cryRpt.ExportOptions
With CrExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
.DestinationOptions = CrDiskFileDestinationOptions
.FormatOptions = CrFormatTypeOptions
End With
cryRpt.Export()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
I get the error "Load Report Failed" on the line
cryRpt.Load(My.Application.Info.DirectoryPath & "\CrystalExport.pdf")
To me it's probably just me doing something stupid, but what do you suggest?
Upvotes: 1
Views: 464
Reputation: 185
you set path up at the top of your code like this
Dim path As String = "H:\Auto Dealer Project\Public"
but then look for your report a different way.
Are you certain the path My.Application.Info.DirectoryPath & "\CrystalExport.pdf" actually leads where you think it does?
Put a break point on that line and make sure the path leads to the right place. Generally you get the load report error if the report doesn't exist (because it's not in the folder you thought it was)
Upvotes: 1