2011-11-17 56 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); 
相關問題