I created this code in ASP.NET which asks no. of files to upload in a text box and then it dynamically createsthat no. of File upload controls. Till here its working fine. But i m unable to save files which should happen when i click on Button. Please help...
Here is my code and i am attaching a snapshot of my website page..
Partial Class member_fileupload
Inherits System.Web.UI.Page
Dim i As Byte, j As Byte
Protected Sub txtnum_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtnum.TextChanged
i = Val(txtnum.Text)
For j = 1 To i
Dim tr As New TableRow()
Dim td1 As New TableCell()
Dim td2 As New TableCell()
Dim fileupload As New FileUpload()
Dim lbltitle As New Label()
Dim txttitle As New TextBox()
lbltitle.Text = "Title for file"
fileupload.ID = "fileupload" & j.ToString
td1.Controls.Add(fileupload)
td2.Controls.Add(New LiteralControl(" "))
td2.Controls.Add(lbltitle)
td2.Controls.Add(New LiteralControl(" "))
td2.Controls.Add(txttitle)
Response.Write(fileupload.ID)
tr.Cells.Add(td1)
tr.Cells.Add(td2)
Table1.Rows.Add(tr)
Next
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim savepath As String = Request.PhysicalApplicationPath
savepath += "uploads\"
Dim ctrl As Control
For Each ctrl In Page.Controls
If TypeOf ctrl Is FileUpload Then
If CType(ctrl, FileUpload).HasFile Then
savepath += CType(ctrl, FileUpload).FileName
CType(ctrl, FileUpload).SaveAs(savepath)
End If
End If
Next
Response.Write("successfull")
End Sub
End Class