我需要在Visual Studio 2010中創建一個C#用戶函數庫,這將允許有人在CR XI中查看報告以電子郵件的形式直接發送報告。創建UFL將報告直接郵寄爲PDF
我從來沒有創建了UFL,我從來沒有使用Crystal Reports的工作,我充分認識到不同的版本是多麼的不兼容的,這是多麼重要的精確理清我會哪一個在能夠完成任何開發之前進行合作。
我需要知道的是......我甚至從哪開始呢?我已經看到類似這樣的一些問題,但大多數都涉及打印報告,而不是通過電子郵件發送。我認識到這與Stack的通常內容相比有點補救,但我沒有太多的運氣讓我的腳在我身下,我自己。任何幫助都將不勝感激。
這是我到目前爲止。點擊第一個按鈕可以預先點擊第二個按鈕應該發送的內容,但似乎並沒有發生任何事情。我被告知System.Web.Mail.SmtpMail
已過時,但還沒有找到任何更好的工作。
private void button1_Click(object sender, EventArgs e)
{
cryRpt = new ReportDocument();
cryRpt.Load("CrystalReport1.cs");
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
}
private void button2_Click(object sender, EventArgs e)
{
try
{
ExportOptions CrExportOptions;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = pdfFile;
CrExportOptions = cryRpt.ExportOptions;
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
cryRpt.Export();
sendmail();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void sendmail()
{
try
{
SmtpMail.SmtpServer.Insert(0, "your hostname");
MailMessage Msg = new MailMessage();
Msg.To = "to address here";
Msg.From = "from address here";
Msg.Subject = "Crystal Report Attachment ";
Msg.Body = "Crystal Report Attachment ";
Msg.Attachments.Add(new MailAttachment(pdfFile));
System.Web.Mail.SmtpMail.Send(Msg);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
我認爲我們正在尋找類似於此的東西 http://www.crystalkeen.com/tools/mail.html – Eiketsu