0

ドキュメントをサーバーに保存せずに電子メールに添付することはできますか?

以下のコードは、サーバーに保存した後にのみ添付されるものです。私が探しているのは、ドキュメントを最初に保存せずにメールに添付する代わりに、提供されたパスからメールに添付することです。

これは、c# を使用した Visual Studio 2005 です。

if (SaveDocument.HasFile)
        {
            /* Get a reference to PostedFile object */               
            string strFileName = Path.GetFileName(SaveDocument.PostedFile.FileName);
                /* Save the file on the server */
            SaveDocument.PostedFile.SaveAs(Server.MapPath(strFileName));
                /* Create the email attachment with the uploaded file */
            System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(Server.MapPath(strFileName));
                /* Attach the newly created email attachment */
            message.Attachments.Add(attach);                  

        }
4

3 に答える 3

0

を に直接渡しPostedFileます。InputStreamAttachment

if (SaveDocument.HasFile)
{
        /* Create the email attachment with the uploaded file */
    System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(SaveDocument.PostedFile.InputStream, "filename");
        /* Attach the newly created email attachment */
    message.Attachments.Add(attach);                  

}

まだ試していませんが、うまくいくはずです。

于 2013-11-12T16:44:46.607 に答える