Effettuare l'upload di pił files contemporaneamente
<%@ Page Language="C#" %>
<script runat="server">
void Button1_Click(object Source, EventArgs e)
{
lbMsg.Text = saveFiles();
}
string saveFiles()
{
string strMessage = "";
string strFileName;
HttpPostedFile objFile;
for (int i=0; i<Request.Files.Count; i++)
{
objFile = Request.Files[i];
if (objFile.FileName != "")
{
strFileName = objFile.FileName;
strFileName = strFileName.Substring(strFileName.LastIndexOf("\\")+1);
try
{
objFile.SaveAs("c:\\mywebs\\uploads\\"+strFileName);
strMessage += "Salvati: c:\\mywebs\\uploads\\" + strFileName + "<br>";
}
catch (Exception err)
{
strMessage+= "Errore: "+strFileName+": "+err.ToString()+"<br>";
}
}
}
return strMessage;
}
</script>
<html>
<body>
<form id="frmUp" enctype="multipart/form-data" runat="server">
<table style="width: 301px">
<tr>
<td>File1</td>
<td style="width: 231px"><input id="txtFile" type="file" runat="server"></td>
</tr>
<tr>
<td>
File2</td>
<td style="width: 231px">
<input id="txtFile2" type="file" runat="server"></td>
</tr>
<tr>
<td>File3</td>
<td style="width: 231px"><input id="txtFile3" type="file" runat="server"></td>
</tr>
<tr>
<td>
</td>
<td style="width: 231px">
<input type=button id="Button1" value="Upload" OnServerClick="Button1_Click" runat="server"></td>
</tr>
<tr>
<td>
</td>
<td style="width: 231px">
<asp:Label ID="lbMsg" runat="server"></asp:Label></td>
</tr>
</table>
</form>
</body>
</html>
Scarica il Codice...
Stampa la pagina