2011-11-17 83 views
0

我试图从网站中的某个文件夹附加一个word文件。 这是我正在尝试:从文件夹附加word文档,c#邮件信息

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

回答

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