我想在邮件中添加pdf文件。
mail.Attachments.Add(new Attachment(path));
pdf路径:http://localhost/WEB/Pages/Customer/PDF/test.pdf
当我运行代码时,它会出错:“URI formats are not supported.
”
但路径是正确的,所以我可以打开它。
我认为预期的路径如C:\\test.pdf
等。但我想从我的项目里面给出路径。怎么做?
答案 0 :(得分:0)
使用Server.MapPath并将路径传递到目录
MailAttachment attachment = new MailAttachment( Server.MapPath( "Pages/Customer/PDF/test.txt" ) ); //create the attachment
mail.Attachments.Add( attachment ); //add the attachment