<script type="text/javascript">
var counter = 0;
function AddFileUpload() {
var div = document.createElement('DIV');
div.innerHTML = '<input id="file' + counter + '" name = "file' + counter +
'" type="file" />' +
'<input id="Button' + counter + '" type="button" ' +
'value="Remove" onclick = "RemoveFileUpload(this)" />';
document.getElementById("FileUploadContainer").appendChild(div);
counter++;
}
function RemoveFileUpload(div) {
document.getElementById("FileUploadContainer").removeChild(div.parentNode);
}
</script>
<form id="form1" runat="server" enctype="multipart/form-data" method="post">
<table>
<tbody>
<tr>
<td>
<span style="font-family: Arial">Click to add files</span>
<input id="Button1" type="button" value="add" onclick="AddFileUpload()" />
<br />
<br />
<div id="FileUploadContainer">
<!--FileUpload Controls will be added here -->
</div>
<br />
</td>
</tr>
<tr>
<td align="left">
<hr />
<asp:Label runat="server" ID="lblFiles"></asp:Label>
</td>
</tr>
</tbody>
</table>
<tbody>
<tr>
<td>
<span style="font-family: Arial">Click to add files</span>
<input id="Button1" type="button" value="add" onclick="AddFileUpload()" />
<br />
<br />
<div id="FileUploadContainer">
<!--FileUpload Controls will be added here -->
</div>
<br />
</td>
</tr>
<tr>
<td align="left">
<hr />
<asp:Label runat="server" ID="lblFiles"></asp:Label>
</td>
</tr>
</tbody>
</table>
</form>
Codebehind:
for (int i = 0; i < Request.Files.Count; i++)
{
HttpPostedFile PostedFile = Request.Files[i];
if (PostedFile.ContentLength > 0)
{
string FileName = System.IO.Path.GetFileName(PostedFile.FileName);
Stream fs = PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
byte[] ba = br.ReadBytes((Int32)fs.Length);
}
}
{
HttpPostedFile PostedFile = Request.Files[i];
if (PostedFile.ContentLength > 0)
{
string FileName = System.IO.Path.GetFileName(PostedFile.FileName);
Stream fs = PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
byte[] ba = br.ReadBytes((Int32)fs.Length);
}
}
No comments:
Post a Comment