title: File are corrupted when Attaching them to MailMessage C#
body: <p>I have created an application at work that generates exel files from some database data. After generating the files they are sent automatically to the customers in question. My problem is that it works fine when i run the published application. But some users when they run the application the files are generated perfectly as they are saved on the HDD and i can see them. But when they are attached to the MailMessage object they get corrupted. This is an image of the corrupted files. These files should be Excel files.</p>
  
  <p><img src="https://i.stack.imgur.com/wOguw.png" alt="enter image description here"></p>
  
  <p>This is my code for sending a mail with attached files:</p>
  
  <pre><code>public void SendMailedFilesDK()
          {
              string[] sentFiles = Directory.GetFiles(sentFilesDK);
              if (sentFiles.Count() &gt; 0)
              {
                  using (System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("ares"))
                  {
                      using (System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage())
                      {
                          msg.From = new MailAddress("system@mail.dk");
                          msg.To.Add(new MailAddress("operation@mail.dk"));
                          msg.To.Add(new MailAddress("bl@mail.dk"));
                          msg.CC.Add("lmy@mail.dk");
                          msg.CC.Add("ltr@mail.dk");
                          msg.Subject = "IBM PUDO";
                          msg.Body = sentFiles.Count() + " attached file(s) has been sent to the customer(s) in question ";
                          msg.IsBodyHtml = true;
                          foreach (string file in sentFiles)
                          {
                              Attachment attachment = new Attachment(file);
                              msg.Attachments.Add(attachment);
                          }
  
                          client.Send(msg);
                      }
                  }
              }
          }
  </code></pre>
  
  <p>Why are the files getting corrupted when others run the application? We are all using office 2010.</p>