簡體   English   中英

嘗試使用For Loop從文件上傳控件中抓取多個文件以將文件附加到電子郵件

[英]Trying to use a For Loop to grab multiple files from a File Upload Control to attach the files to email

這里發生的事情是我可以循環獲取文件。 問題是說我有2個文件是從asp.net/jquery多個上傳控件生成的,它抓住了第一個附件3次,然后看不到第二個附件。 因此,文件將兩次生成到Outlook的附件區域中。 這是我的代碼:

        HttpFileCollection fileCollection = Request.Files;
        for (int i = 0; i < fileCollection.Count; i++)
        {
            HttpPostedFile uploadfile = fileCollection[i];
            string strFileName = Path.GetFileName(uploadfile.FileName);
            Attachment attachFile = new Attachment(multipleFile.PostedFile.InputStream,      strFileName);
            mailmessage.Attachments.Add(attachFile);

                //uploadfile.SaveAs(Server.MapPath("~/Photos/") + strFileName);
                mailmessage.Attachments.Add(attachFile);
                lblMessage.Text += strFileName + "   " + "Saved Successfully<br>";

        }

我不了解我的For Loop發生了什么,但對我來說似乎應該可以工作。

使用在流uploadfile對象-並除去呼叫之一mailmessage.Attachments.Add() -

HttpFileCollection fileCollection = Request.Files;
for (int i = 0; i < fileCollection.Count; i++)
{
    HttpPostedFile uploadfile = fileCollection[i];
    string strFileName = Path.GetFileName(uploadfile.FileName);
    Attachment attachFile = new Attachment(uploadfile.InputStream, strFileName);

    //uploadfile.SaveAs(Server.MapPath("~/Photos/") + strFileName);
    mailmessage.Attachments.Add(attachFile);
    lblMessage.Text += strFileName + "   " + "Saved Successfully<br>";
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM