on 06-03-2013 8:58 AM
good day sir,
this is my whole code for creating a crystal report and exporting it to a pdf file:
Public Sub rsvrpt()
Dim rpt As New reservationrpt() 'The report you created.
Dim MyCommand As New SqlCommand()
Dim myDA As New SqlDataAdapter()
Dim myDS As New DataSet2() 'The DataSet you created.
Dim cn As New SqlConnection(ConnectString())
Try
MyCommand.Connection = cn
MyCommand.CommandText = "SELECT * FROM maintable where irsno=" + irsn + " And branchID='" + branch + "'"
MyCommand.CommandType = CommandType.Text
myDA.SelectCommand = MyCommand
myDA.Fill(myDS, "maintable")
'myDA.SelectCommand.CommandText = "Select fullname from usertbl where username='" + Login.txtuser.Text + "'"
'myDA.Fill(myDS, "usertbl")
myDA.SelectCommand.CommandText = "Select * from roomtbl where irsno=" + irsn + " And branchID='" + branch + "'"
myDA.Fill(myDS, "roomtbl")
myDS.EnforceConstraints = False
rpt.SetDataSource(myDS)
CrystalReportViewer1.ReportSource = rpt
'rpt.PrintOptions.PrinterName = "EPSON LX-300+ /II"
'rpt.PrintToPrinter(1, False, 0, 0)
Catch Excep As Exception
MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
Try
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
CrDiskFileDestinationOptions.DiskFileName = "C:\Users\Frontliner0102\Desktop\reservation.pdf"
CrExportOptions = rpt.ExportOptions
With CrExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
.DestinationOptions = CrDiskFileDestinationOptions
.FormatOptions = CrFormatTypeOptions
End With
rpt.Export()
Catch ex As Exception
End Try
End Sub
i want to send the crystal report to an email using microsoft outlook but i dont have any idea how to start it.can anyone give me some advice or guide on how to dot it? I searched throughout the internet but all i have read is that using SMPT server.
Hello,
You can do it this way:
exportOpts.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.MicrosoftMail;
exportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
mailOpts.MailToList = "Don Williams";
mailOpts.MailSubject = "Attached is a PDF file - .net Export test ";
mailOpts.MailSubject = "This is the Subject";
//MailOpts.MailCCList = "John Doe";
mailOpts.UserName = "NetworkUserName";
mailOpts.Password = "pw";
exportOpts.ExportDestinationOptions = mailOpts;
rpt.Export(exportOpts);
MessageBox.Show("Mail sent Completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
Requires MAPI or the MS Client to be installed.
If Outlook is not available then we need to know what version of CR runtime you are using?
If it's not available then export to Disk and then use Outlook API's to send an e-mail as an attachment.
Don
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Good Day sir, this is my code so far:
Dim fname As String = "C:\Users\Frontliner0102\Desktop\reservation.pdf"
Dim OutlookMessage As outlook.MailItem
Dim AppOutlook As outlook.Application
Try
OutlookMessage = AppOutlook.CreateItem(outlook.OlItemType.olMailItem)
Dim Recipents As outlook.Recipients = OutlookMessage.Recipients
Recipents.Add("chestercc@izones.com.ph")
OutlookMessage.To = txtEmail.Text
OutlookMessage.Subject = "Sending through Outlook"
OutlookMessage.Body = "Testing outlook Mail"
OutlookMessage.BodyFormat = outlook.OlBodyFormat.olFormatHTML
Dim oAttach As outlook.Attachment
oAttach = OutlookMessage.Add(fname)
OutlookMessage.Send()
Catch ex As Exception
'MessageBox.Show("Mail could not be sent") 'if you dont want this message, simply delete this line
Finally
OutlookMessage = Nothing
AppOutlook = Nothing
End Try
my code does.not send an attachment email to the given email address. i am using vs.net2010 and crystal report version 13
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.