Reputation: 2404
I currently have a slight issue with attaching a word document to an email message in the Graph API.
I can send the email absolutely fine if i point the path to the location on the server, however as theres the possibility this may change, i want to use a copy which is held within the project structure in /Content/Docs/File.docx. However if i use the path ~/Content/Docs/File.docx
it looks for the file in the IIS directory of Program Files. If i remove the ~
then it looks for the content directory in the C:/ drive. Does anybody know how i can get around this and use a version of the file within the application?
My code is below:
using(var msg = new MailMessage())
{
msg.Subject = string.Format("This is the subject");
msg.Body = string.Format("This is the message body");
msg.Attachments.Add(new Attachment("~/Content/Docs/File.docx"));
await SendMessage(msg, emailAddress);
}
Many Thanks,
Upvotes: 1
Views: 1438
Reputation: 17692
As Edgaras pointed out, using Server.MapPath
to get a fully-qualified path will help you here.
Upvotes: 1