使用Windows窗体邮寄水晶报表时出现问题 [英] Problem in mailing a crystal report using windows Forms
问题描述
嗨..
我正在尝试使用Windows窗体邮寄一份水晶报告.
我正在使用指令Using System.Web.Mail;
但我收到错误消息.
错误是System.Web.Mail.SmtpMail已过时.推荐的替代方法是System.Net.Mail.SmtpClient.
我尝试使用替代方法,但无法发送.
另外我还需要知道主机名.
我需要输入主机名..
请帮助
我正在使用以下代码
Hi..
I am trying to mail a crystal report using windows forms.
i am using the directive Using System.Web.Mail;
but im getting an error.
The Error is System.Web.Mail.SmtpMail is obsolete.Recommended Alternative is System.Net.Mail.SmtpClient.
I tried using the alternative but m not able to send it.
plus i also need to know the host name.
i need to enter the Host name..
Please Help
i am using the following code
public partial class Medicinesrep : Form
{
ReportDocument cryRpt;
string pdfFile = ".........."
public Medicinesrep()
{
InitializeComponent();
}
private void Medicinesrep_Load(object sender, EventArgs e)
{
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load(".............")
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
}
private void button1_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, "POP/SMTP");
MailMessage Msg = new MailMessage();
Msg.To = "mishraneilabh@gmail.com";
Msg.From = "mishraneilabh@gmail.com";
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());
}
}
}
}
[edit]伪造的代码块已删除-OriginalGriff [/edit]
[edit]spurious code block removed - OriginalGriff[/edit]
推荐答案
此处有一个使用Net.Mail的示例: ^ ]
There is an example using Net.Mail here: Sending an Email in C# with or without attachments: generic routine.[^]
非常感谢您的帮助..:)
Thank u so much for the help.. :)
这篇关于使用Windows窗体邮寄水晶报表时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!