我創建了一個應用程序,用於從某些數據庫數據生成exel文件。生成文件後,它們會自動發送給相關客戶。我的問題是,當我運行發佈的應用程序時,它工作正常。但是有些用戶在運行應用程序時會生成完美的文件,因爲它們保存在硬盤上,我可以看到它們。但是當它們連接到MailMessage對象時,它們會被損壞。這是損壞文件的圖像。這些文件應該是Excel文件。將它們附加到MailMessage時文件已損壞C#
這是我的郵件發送帶有附件代碼:
public void SendMailedFilesDK()
{
string[] sentFiles = Directory.GetFiles(sentFilesDK);
if (sentFiles.Count() > 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("[email protected]");
msg.To.Add(new MailAddress("[email protected]"));
msg.To.Add(new MailAddress("[email protected]"));
msg.CC.Add("[email protected]");
msg.CC.Add("[email protected]");
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);
}
}
}
}
爲什麼文件越來越損壞當別人運行應用程序?我們都在使用office 2010.
如果它是我需要attatch的Zip文件,我應該寫什麼?我試圖插入這一行:**附件附件=新的附件(zipFile,MediaTypeNames.Application.Zip); **但它沒有奏效。我正在使用** DotNetZipLib-DevKit-v1.9 ** – Lahib 2013-03-22 09:56:48
發現它。我必須使用'application/zip' – Lahib 2013-03-22 10:07:48