none
to send separate pdf file for each customer RRS feed

  • Question

  • Hi,

    Anybody can share an idea in C# how to implement the form bases c# program how to send email to customers as separate pdf using RDLC reportviewer. The rdlc report should not show up to the user. the pdf should be generated for each customer code in the datagridview. Any help would be very appreciate.

    If not possible in RDLCm is there any alternate solution.

    Pol


    polachan

    Thursday, April 7, 2016 7:50 AM

All replies

  • You can use the code below to send an email with attachment.

    using System.Net.Mail;
    
    namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                try
                {
                    MailMessage mail = new MailMessage();
                    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
                    mail.From = new MailAddress("your_email_address@gmail.com");
                    mail.To.Add("to_address");
                    mail.Subject = "Test Mail - 1";
                    mail.Body = "mail with attachment";
    
                    System.Net.Mail.Attachment attachment;
                    attachment = new System.Net.Mail.Attachment("your attachment file");
                    mail.Attachments.Add(attachment);
    
                    SmtpServer.Port = 587;
                    SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
                    SmtpServer.EnableSsl = true;
    
                    SmtpServer.Send(mail);
                    MessageBox.Show("mail Send");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
    

    Put your emails in a List so you can loop through them.

    chanmm


    chanmm

    Thursday, April 7, 2016 8:09 AM
  • My question was actually meant  how can create multiple pdf file  dynamically, for each row on a datagridview . 

    Sorry for confusing you 

    Pol


    polachan

    Thursday, April 7, 2016 2:04 PM
  • To create pdf then you need the 3rd party library. I found a pdfsharp http://csharp.net-informations.com/file/create-pdf.ht.

    The code is quite straightforward.

    PdfDocument pdf = new PdfDocument();
                pdf.Info.Title = "My First PDF";
                PdfPage pdfPage = pdf.AddPage();
                XGraphics graph = XGraphics.FromPdfPage(pdfPage);
                XFont font = new XFont("Verdana", 20, XFontStyle.Bold);
                graph.DrawString("This is my first PDF document", font, XBrushes.Black, new XRect(0, 0, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.Center);
                string pdfFilename = "firstpage.pdf";
                pdf.Save(pdfFilename);
                Process.Start(pdfFilename);
     But depend on what is the document in your databridview you are pointing too. So you might need add additional coding.

    chanmm


    chanmm

    Thursday, April 7, 2016 11:49 PM
  • Hi Pol,

    >>If not possible in RDLCm is there any alternate solution.

    From above message, your case also more related to RDLC, I will help move your case to Report Viewer forum for better support.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 11, 2016 9:11 AM