Laziale
Laziale

Reputation: 8225

attach word document from folder, c# mail message

I am trying to attach a word file from one of the folders in the website. This is how I am trying:

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

I am getting these errors:

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'

Any idea how I can solve this? Thanks in advance, Laziale

Upvotes: 0

Views: 3154

Answers (2)

Jason
Jason

Reputation: 89214

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

Upvotes: 1

drdwilcox
drdwilcox

Reputation: 3951

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

Upvotes: 0

Related Questions