I have an ASP.net web application which saves all details entered in the session and at the end, sends an email with all the details including an attachment of the file uploaded (all this currently works fine).
The issue I have is that a change is required to the file upload page. I want to now be able to upload multiple docs, but separately, so basically the user finds the file to upload then clicks an 'Add' button. The upload file field should then clear and a table should populate with the uploaded file(s) with a 'Remove/Delete' button for each file uploaded.
The details that should be displayed in this table are:
- File name
- Option selected form the new dropdown list
- Remove button
As I said I have single file upload working using the code behind but I have no idea how to implement what I'm after so that all uploaded doc's are sent in my email.
Current 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>
Current Code Behind
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";
}
}
My code behind does not capture the option selected but will need to so I can display it on my confirmation page (HTML shown below)
<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>