Multi-file upload
This article show how to save a file to
upload multiple files at once
.
[View
Sample C#]
[View Sample VB.NET]
In order to upload miltiple files at once you will have to follow this
steps:
-
Handle onchange event and add a new input control
<input id="McFileUp" onchange="NextFile()" type="file" name="McFileUp" />
<script language= "javascript">
function NextFile()
{
var coll = document.getElementsByName("McFileUp");
var LatestFile = coll[coll.length - 1];
var objBr = document.createElement("<br>");
LatestFile.insertAdjacentElement("afterEnd", objBr);
var objFile = document.createElement('<input type="file" name="McFileUp" onchange="NextFile()" ID="File1">');
objBr.insertAdjacentElement("afterEnd", objFile);
}
</script>
-
Handle submit event on the server-side and extract incoming files
for(int Index = 0; Index<Request.Files.Count; Index++)
{
using(McHttpPostedFile PostedFile = new McHttpPostedFile(Request.Files[Index])
{
if(PostedFile.FileName!="")
{
// TODO: Save File Here
}
}
}