Effettuare l'upload di più files contemporaneamente
<%@ Page Language="VB" %>
<%@ import Namespace="System.IO" %>
<HTML>
<script language="vbscript" runat="server">
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
lbMsg.Text = saveFiles()
End Sub
Private Function saveFiles()
Dim strMessage As String = ""
Dim strFileName As String
Dim objFile As HttpPostedFile
Dim i As Integer
For i = 0 To Request.Files.Count - 1
objFile = Request.Files(i)
If (objFile.FileName <> "") Then
strFileName = objFile.FileName
strFileName = strFileName.Substring(strFileName.LastIndexOf("\") + 1)
Try
objFile.SaveAs("c:\mywebs\uploads\" + strFileName)
strMessage += "Salvati: c:\mywebs\uploads\" & strFileName + "<br>"
Catch err As Exception
strMessage += "Errore: " + strFileName + ": " & err.ToString() + "<br>"
End Try
End If
Next
Return strMessage
End Function
</script>
<body>
<form id="frmUp" enctype="multipart/form-data" runat="server">
<table style="WIDTH: 301px">
<tr>
<td>File1</td>
<td width="231"><input id="txtFile" type="file" runat="server" NAME="txtFile"></td>
</tr>
<tr>
<td>File2</td>
<td width="231"><input id="txtFile2" type="file" runat="server" NAME="txtFile2"></td>
</tr>
<tr>
<td>File3</td>
<td width="231"><input id="txtFile3" type="file" runat="server" NAME="txtFile3"></td>
</tr>
<tr>
<td>
</td>
<td width="231">
<input type="button" id="Button1" value="Upload"
OnServerClick="Button1_Click" runat="server"></td>
</tr>
<tr>
<td>
</td>
<td width="231">
<asp:Label ID="lbMsg" runat="server"></asp:Label></td>
</tr>
</table>
</form>
</body>
</HTML>