Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 Can';我不知道如何使用MvcMailer进行附件_Asp.net Mvc 3_Mvcmailer - Fatal编程技术网

Asp.net mvc 3 Can';我不知道如何使用MvcMailer进行附件

Asp.net mvc 3 Can';我不知道如何使用MvcMailer进行附件,asp.net-mvc-3,mvcmailer,Asp.net Mvc 3,Mvcmailer,如何以及在何处放置字符串的实际文件位置attachmentPath: public virtual MailMessage Welcome(string attachmentPath) { var mailMessage = new MailMessage{Subject = "Welcome to MvcMailer"}; ... mailMessage.Attachments.Add(new Attachment(attachmentP

如何以及在何处放置字符串的实际文件位置
attachmentPath

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

您可以执行以下操作:

mailMessage.Attachments.Add(new Attachment((Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\docs\") + attachmentFile))
其中attachmentFile是您的文件
test.pdf


c:\inetpub\server\website\docs\test.pdf

只需将attachmentPath替换为@“c:\inetpub\server\website\docs\test.pdf”,如下所示:

mailMessage.Attachments.Add(new Attachment((Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\docs\") + attachmentFile))
mailMessage.Attachments.Add(new Attachment(@"c:\inetpub\server\website\docs\test.pdf"));
更改附件路径

mailMessage.Attachments.Add(new Attachment(attachmentPath));
至@“c:\inetpub\server\website\docs\test.pdf”


很抱歉反应太晚。我到底在哪里“声明”(如果是这样的话)
attachmentFile
?我如何“申报”呢?