2012-07-26 53 views
1

究竟如何,何地,做我把實際的文件位置的字符串attachmentPath想不通怎麼辦附件與MvcMailer

public virtual MailMessage Welcome(string attachmentPath) 
    { 
     var mailMessage = new MailMessage{Subject = "Welcome to MvcMailer"}; 
     ... 
     mailMessage.Attachments.Add(new Attachment(attachmentPath)); 
     PopulateBody(mailMessage, "Welcome"); 
     return mailMessage; 
    } 

設定的c:\inetpub\server\website\docs\test.pdf

服務器上的物理文件位置

回答

1

只需更換爲@ attachmentPath 「C:\的Inetpub \服務器\網站\文檔\檢驗.pdf」 是這樣的:

更改attachmentPath

mailMessage.Attachments.Add(new Attachment(attachmentPath)); 

爲@ 「C:\的Inetpub \服務器\網站\文檔\檢驗.pdf」

mailMessage.Attachments.Add(new Attachment(@"c:\inetpub\server\website\docs\test.pdf")); 
1

你會做這樣的事情:

mailMessage.Attachments.Add(new Attachment((Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\docs\") + attachmentFile)) 

哪裏attachmentFile是您的文件test.pdf

C:\的Inetpub \服務器\網站\文檔\檢驗.pdf

+0

對不起,我遲到的反應。我究竟在哪裏「宣佈」(如果是這樣)'attachmentFile'?我該如何「聲明」它? – REMESQ 2012-07-29 14:57:00