прикрепить текстовый документ из папки, почтовое сообщение c # - PullRequest
0 голосов
/ 17 ноября 2011

Я пытаюсь прикрепить файл слова из одной из папок на сайте.Вот как я пытаюсь:

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'

Любая идея, как я могу решить эту проблему?Заранее спасибо, Лазиале

Ответы [ 2 ]

1 голос
/ 18 ноября 2011
string path = HttpContext.Current.Server.MapPath(@"Docs\" + companyName + ".doc");
Attachment attachment = new Attachment(path);
msg.Attachments.Add(attachment);
0 голосов
/ 17 ноября 2011
Attachment a = new Attachment(HttpContext.Current.Server.MapPath(@"Docs\" + companyName + ".doc"));
msg.Attachments.Add(a);
...