2016-03-29 9 views
0

私はASP.netウェブアプリケーションを持っており、セッションに入力されたすべての詳細を保存し、最後にアップロードされたファイルの添付ファイルを含むすべての詳細を含むメールを送信します。Asp.net複数のファイルアップロード

問題は、ファイルのアップロードページに変更が必要だということです。複数のドキュメントをアップロードできるようになりましたが、個別にアップロードするファイルを見つけて[追加]ボタンをクリックすると、基本的にユーザーはファイルをアップロードできます。アップロードファイルフィールドはクリアされ、アップロードされた各ファイルの '削除/削除'ボタンを使用して、アップロードされたファイルがテーブルに表示されます。このテーブルに表示されなければならない

の詳細は以下のとおりです。

  • ファイル名
  • オプション選択したフォーム私は、単一の持って言ったように、新しいドロップダウンリスト
  • 削除]ボタン

コードの背後にあるコードを使用してファイルをアップロードしていますが、アップロードしたすべてのドキュメントが自分のメールで送信されるように、どのように実装するのか分かりません。

現在のHTML

<div class="form-group"> 
    <div class="col-sm-offset-2 col-sm-5"> 
      <div class="fileinput fileinput-new input-group" data-provides="fileinput"> 
       <div class="form-control" data-trigger="fileinput" style="background-color: #ededed"> 
        <span class="fileinput-filename"></span> 
       </div> 
       <span class="input-group-addon btn btn-default btn-file"> 
        <span class="fileinput-new"> 
         <span class="glyphicon glyphicon-folder-open" title="Click to select a file."></span> 
        </span> 
        <span class="fileinput-exists"> 
         <span class="glyphicon glyphicon-folder-open" title="Click to change the selected file."></span> 
        </span> 
        <input type="file" name="..." id="fuAttachment" runat="server" /> 
       </span> 
      </div> 
    </div> 
    <div class="col-sm-3"> 
      <asp:DropDownList ID="Step03WebTypeDD" runat="server" class="form-control"> 
       <asp:ListItem Value="- - Please select - -">- - Please select - -</asp:ListItem> 
       <asp:ListItem Value="Requirements">Requirements</asp:ListItem> 
       <asp:ListItem Value="Functional specification">Functional specification</asp:ListItem> 
       <asp:ListItem Value="Page Content">Page Content</asp:ListItem> 
       <asp:ListItem Value="Page Designs">Page Designs</asp:ListItem> 
       <asp:ListItem Value="Page Designs">Other</asp:ListItem> 
      </asp:DropDownList> 
    </div> 
    <div class="col-sm-1">          
      <asp:LinkButton ID="UploadAddButton" runat="server" OnClick="Step05UploadAddButton_Click" CssClass="btn btn-success pull-right" ToolTip="Click to upload the file."> 
       <span class="glyphicon glyphicon-plus"></span> Add 
      </asp:LinkButton> 
    </div> 
</div> 

現在のコードの後ろ

protected void Step05UploadAddButton_Click(object sender, EventArgs e) 
{ 
    var file = fuAttachment.PostedFile; 
    if (file != null && fuAttachment.PostedFile.FileName != "") 
    { 
      var content = new byte[file.ContentLength]; 
      file.InputStream.Read(content, 0, content.Length); 
      Session["FileContent"] = content; 
      Session["FileContentType"] = file.ContentType; 
      Session["File"] = fuAttachment.PostedFile.FileName; 
      Session["AttachmentProvided"] = "Yes"; 
    } 
    else 
    { 
      Session["FileContent"] = ""; 
      Session["FileContentType"] = ""; 
      Session["File"] = ""; 
      Session["AttachmentProvided"] = "No"; 
    } 
} 

私のコードの後ろに選択されたオプションを取得しませんが、私は私の確認ページに表示することができますする必要があります(以下に示すHTML)

<div class="form-group"> 
     <asp:Label ID="Label6" class="col-xs-6 col-sm-3 control-label" runat="server" Text="Attachment provided:"></asp:Label> 
     <div class="col-xs-6 col-sm-9 form-control-static"> 
      <% if (Session["AttachmentProvided"] == "Yes") 
      {%> 
       Yes (<%=Session["File"] %>) 
      <%} 
      else 
      { %> 
       No 
      <%} %> 
     </div> 
    </div> 

答えて

1

JavaScriptを使用してDOMに追加の<input type="file" />要素を追加し、MSDNで説明したようにRequest.Filesを使用するすべてのファイルを総称して参照できます。 MSDNから取られたサンプル:

Files = Request.Files; // Load File collection into HttpFileCollection variable. 
arr1 = Files.AllKeys; // This will get names of all files into a string array. 
for (loop1 = 0; loop1 < arr1.Length; loop1++) 
{ 
    Response.Write("File: " + Server.HtmlEncode(arr1[loop1]) + "<br />"); 
    Response.Write(" size = " + Files[loop1].ContentLength + "<br />"); 
    Response.Write(" content type = " + Files[loop1].ContentType + "<br />"); 
}