从文件夹,c#邮件附加word文档

时间:2011-11-17 19:56:24

标签: c# asp.net attachment sendmail

我正在尝试从网站的其中一个文件夹中附加一个word文件。 这就是我的尝试:

Attachment attachment = new Attachment(msg.Attachments.Add(HttpContext.Current.Server.MapPath(@"Docs\" + companyName + ".doc")));

我收到了这些错误:

The best overloaded method match for 'System.Collections.ObjectModel.Collection<System.Net.Mail.Attachment>.Add(System.Net.Mail.Attachment)' has some invalid arguments 
cannot convert from 'void' to 'string'  
cannot convert from 'string' to 'System.Net.Mail.Attachment'

知道如何解决这个问题吗? 在此先感谢Laziale

2 个答案:

答案 0 :(得分:1)

string path = HttpContext.Current.Server.MapPath(@"Docs\" + companyName + ".doc");
Attachment attachment = new Attachment(path);
msg.Attachments.Add(attachment);

答案 1 :(得分:0)

Attachment a = new Attachment(HttpContext.Current.Server.MapPath(@"Docs\" + companyName + ".doc"));
msg.Attachments.Add(a);