Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3213920
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:00:00+00:00 2026-05-17T15:00:00+00:00

Our winforms application has long allowed a print option which basically uses RDLC. The

  • 0

Our winforms application has long allowed a “print” option which basically uses RDLC.

The customer has requested that we add a feature allowing users to send the “printed” output via email.

Now, we know that an EMF file is created (in the TEMP folder) as a sort of hidden byproduct of our current printing process.

Seems to us we can simply grab this EMF file and attach it to a new email and the job is done.

  1. Is this the best option?
  2. Can we rely on an EMF file be opened by any Windows machine?
  3. How we identify the EMF file? … just seems to be named %TEMP%\DiaryGrid_1.emf currently. OK so DiaryGrid is the name of our RDLC file but the _1 gets added somewhere along the way.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:00:01+00:00Added an answer on May 17, 2026 at 3:00 pm

    I did it before. I did it exporting programatically the report to a pdf to a specific location, then we email the pdf file and delete it. I will try to find the code for you (Not in home now)

    EDITED:

    Sorry for the later. Now i’m in home and I will give you some code blocks that I think will give you some help to acomplish your task. I will include some comments to the code so you can understand some things that are specific in my project. This code are tested and are working well in my clients, but i’m sure that it can be improved. Please, let me know if you can improve this code 😉

    First of all, we will export the report to pdf.

    private string ExportReportToPDF(string reportName)
    {
       Warning[] warnings;
       string[] streamids;
       string mimeType;
       string encoding;
       string filenameExtension;
       byte[] bytes = ReportViewer1.LocalReport.Render(
          "PDF", null, out mimeType, out encoding, out filenameExtension,
           out streamids, out warnings);
    
       string filename = Path.Combine(Path.GetTempPath(), reportName);
       using (var fs = new FileStream(filename, FileMode.Create))
       {
          fs.Write(bytes, 0, bytes.Length);
          fs.Close();
       }
    
       return filename;
    }
    

    Now, we need a class that control the Mail system. Every mail system has their own caracteristics, so maybe you will need modify this class. The behaviour of the class is simple. You only need to fill the properties, and call the Send method. In my case, windows don’t let me delete the pdf file once I send it (Windows says the file is in use), so I program the file to be deleted in the next reboot. Take a look to the delete method. Please, note that the send method use a cutom class named MailConfig. This is a small class that has some config strings like Host, User Name, and Password. The mail will be send using this params.

    public class Mail
    {
       public string Title { get; set; }
       public string Text { get; set; }
       public string From { get; set; }
       public bool RequireAutentication { get; set; }
       public bool DeleteFilesAfterSend { get; set; }
    
       public List<string> To { get; set; }
       public List<string> Cc { get; set; }
       public List<string> Bcc { get; set; }
       public List<string> AttachmentFiles { get; set; }
    
       #region appi declarations
    
       internal enum MoveFileFlags
       {
          MOVEFILE_REPLACE_EXISTING = 1,
          MOVEFILE_COPY_ALLOWED = 2,
          MOVEFILE_DELAY_UNTIL_REBOOT = 4,
          MOVEFILE_WRITE_THROUGH = 8
       }
    
       [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
       static extern bool MoveFileEx(string lpExistingFileName,
                                     string lpNewFileName,
                                     MoveFileFlags dwFlags);
    
       #endregion
    
       public Mail()
       {
          To = new List<string>();
          Cc = new List<string>();
          Bcc = new List<string>();
          AttachmentFiles = new List<string>();
          From = MailConfig.Username;
       }
    
       public void Send()
       {
          var client = new SmtpClient
          {
             Host = MailConfig.Host,
             EnableSsl = false,
          };
    
          if (RequireAutentication)
          {
             var credentials = new NetworkCredential(MailConfig.Username, 
                                                     MailConfig.Password);
             client.Credentials = credentials;
          }
    
          var message = new MailMessage
          {
             Sender = new MailAddress(From, From),
             From = new MailAddress(From, From)
          };
    
          AddDestinataryToList(To, message.To);
          AddDestinataryToList(Cc, message.CC);
          AddDestinataryToList(Bcc, message.Bcc);
    
          message.Subject = Title;
          message.Body = Text;
          message.IsBodyHtml = false;
          message.Priority = MailPriority.High;
    
          var attachments = AttachmentFiles.Select(file => new Attachment(file));
          foreach (var attachment in attachments)
             message.Attachments.Add(attachment);
    
          client.Send(message);
    
          if (DeleteFilesAfterSend)
             AttachmentFiles.ForEach(DeleteFile);
       }
    
       private void AddDestinataryToList(IEnumerable<string> from,
          ICollection<MailAddress> mailAddressCollection)
       {
          foreach (var destinatary in from)
             mailAddressCollection.Add(new MailAddress(destinatary, destinatary));
       }
    
       private void DeleteFile(string filepath)
       {
          // this should delete the file in the next reboot, not now.
          MoveFileEx(filepath, null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
       }
    }
    

    Now, you can create a form to ask for the destinataries, add some validation, etc, return to you an instance of the Mail class… or you can simply “hard code” the values and fill the class.

    Here is the code that I use in a button to call this form, in my example it is named SendMailView.

    private void BtnSendByMail_Click(object sender, EventArgs e)
    {
       SendMailView sendMailView = new SendMailView();
    
       if (sendMailView.ShowDialog()== DialogResult.OK)
       {
          Mail mail = sendMailView.CurrentItem;
          mail.AttachmentFiles.Add(ExportReportToPDF("Invoice.pdf"));
          mail.DeleteFilesAfterSend = true;
          mail.RequireAutentication = true;
          mail.Send();
       }
       sendMailView.Dispose();
    }
    

    In this example senMailView.CurrentItem is the instance of the mail class. We simply need to call to the Send methis and the work is done.

    This is the largest answer I ever wrote in SO… I hope it help you 😀 If you have any problem using it, call me. By the way, i’m not very proud of my english, so forgive me if the text has any mistake.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.