[code] <tr valign="top" id="fileInput0"> <td><b>文件 1:</b></td> <td><INPUT id="UploadFile1" type="file" size="40" name="UploadFile1" runat="server"> </td> </tr> <tr valign="top" id="fileInput1"> <td><b>文件 2:</b></td> <td><INPUT id="UploadFile2" type="file" size="40" name="UploadFile2" runat="server"></td> </tr> <tr valign="top" id="fileInput2"> <td><b>文件 3:</b></td> <td><INPUT id="UploadFile3" type="file" size="40" name="UploadFile3" runat="server"></td> </tr> <tr valign="top" id="fileInput3"> <td><b>文件 4:</b></td> <td><INPUT id="UploadFile4" type="file" size="40" name="UploadFile4" runat="server"></td> </tr> <tr valign="top" id="fileInput4"> <td><b>文件 5:</b></td> <td><INPUT id="UploadFile5" type="file" size="40" name="UploadFile5" runat="server"></td> </tr> [/code][code] 'FileCount就是上传文件的个数 Public ReadOnly Property FileCount() As Integer Get Dim i As Integer Dim c As Control Dim f As HtmlInputFile _fileCount = 0 For Each c In Me.Controls If TypeOf c Is HtmlInputFile Then f = CType(c, HtmlInputFile) If (Not (f.PostedFile Is Nothing)) AndAlso (f.PostedFile.FileName <> "") Then If isTargetFile(f.PostedFile) Then _fileCount += 1 End If End If End If Next Return _fileCount End Get End Property 'Files(i)返回指定的上传文件HttpPostedFile Public ReadOnly Property Files(ByVal index As Integer) As HttpPostedFile Get Dim i As Integer = 0 Dim c As Control Dim f As HtmlInputFile For Each c In Me.Controls If TypeOf c Is HtmlInputFile Then f = CType(c, HtmlInputFile) If (Not (f.PostedFile Is Nothing)) AndAlso (f.PostedFile.FileName <> "") Then If isTargetFile(f.PostedFile) Then i += 1 If i = index Then Return f.PostedFile End If End If End If End If Next End Get End Property [/code] 用FileCount来判断文件个数,然后用Files(i)来访问具体的文件对象 这就和上传单个文件一样了
<tr valign="top" id="fileInput0">
<td><b>文件 1:</b></td>
<td><INPUT id="UploadFile1" type="file" size="40" name="UploadFile1" runat="server">
</td>
</tr>
<tr valign="top" id="fileInput1">
<td><b>文件 2:</b></td>
<td><INPUT id="UploadFile2" type="file" size="40" name="UploadFile2" runat="server"></td>
</tr>
<tr valign="top" id="fileInput2">
<td><b>文件 3:</b></td>
<td><INPUT id="UploadFile3" type="file" size="40" name="UploadFile3" runat="server"></td>
</tr>
<tr valign="top" id="fileInput3">
<td><b>文件 4:</b></td>
<td><INPUT id="UploadFile4" type="file" size="40" name="UploadFile4" runat="server"></td>
</tr>
<tr valign="top" id="fileInput4">
<td><b>文件 5:</b></td>
<td><INPUT id="UploadFile5" type="file" size="40" name="UploadFile5" runat="server"></td>
</tr>
[/code][code]
'FileCount就是上传文件的个数
Public ReadOnly Property FileCount() As Integer
Get
Dim i As Integer
Dim c As Control
Dim f As HtmlInputFile
_fileCount = 0
For Each c In Me.Controls
If TypeOf c Is HtmlInputFile Then
f = CType(c, HtmlInputFile)
If (Not (f.PostedFile Is Nothing)) AndAlso (f.PostedFile.FileName <> "") Then
If isTargetFile(f.PostedFile) Then
_fileCount += 1
End If
End If
End If
Next
Return _fileCount
End Get
End Property 'Files(i)返回指定的上传文件HttpPostedFile
Public ReadOnly Property Files(ByVal index As Integer) As HttpPostedFile
Get
Dim i As Integer = 0
Dim c As Control
Dim f As HtmlInputFile
For Each c In Me.Controls
If TypeOf c Is HtmlInputFile Then
f = CType(c, HtmlInputFile)
If (Not (f.PostedFile Is Nothing)) AndAlso (f.PostedFile.FileName <> "") Then
If isTargetFile(f.PostedFile) Then
i += 1
If i = index Then
Return f.PostedFile
End If
End If
End If
End If
Next
End Get
End Property
[/code] 用FileCount来判断文件个数,然后用Files(i)来访问具体的文件对象
这就和上传单个文件一样了