G
Guest
Hi,
I'm developing a web application where users can upload multiple files to
the website.
I'm using asp.net 2.0 with FileUpload control and can upload 1 image to the
server, but I would like to upload 5 images in total.
Can someone help me in writing a VB.NET part on how I can upload these
multiple files using the FileUpload control?
Dim UploadPath As String = Request.PhysicalApplicationPath + "\images\"
'Before attempting to save the file, verify that the FileUpload
Control contains a file.
If (FileUpload1.HasFile) Then
'Get the name of the file to upload.
Dim fileName As String = FileUpload1.FileName
'Get the extension of the upload file.
Dim extension As String = System.IO.Path.GetExtension(fileName)
'Allow only files with .JPEG or .GIF extensions
If (extension = ".jpeg") Or (extension = ".gif") Then
'Get the size in bytes of the file uploaded.
Dim FileSize As Integer = FileUpload1.PostedFile.ContentLength
'Allow only files less than 5,100,000 bytes (Approximately 5
MB) to be uploaded.
If (FileSize < 800000) Then
'Append the name of the uploaded file to the path.
UploadPath += FileUpload1.FileName
'Call the SaveAs method to save the uploaded file.
FileUpload1.PostedFile.SaveAs(UploadPath)
'Notify the user that the file has been uploaded
successfully.
FileUploadReport.Text = "<b>Bestand is opgeladen naar de
website vanaf: </b><br>" & _
FileUpload1.PostedFile.FileName & _
"Content Type " & FileUpload1.PostedFile.ContentType & _
"Length " & FileUpload1.PostedFile.ContentLength
SqlDataSource1.Insert()
Else
FileUploadReport.Text = "<b>Foto is niet opgeladen omdat
het bestand groter is dan 800K!</b><br>"
End If
Else
'Notify the user why their file was not uploaded.
FileUploadReport.Text = "<b>Bestand is niet opgeslagen, dit
omdat U niet het juiste formaat hebt geselecteerd!</b><br>" + _
"<b>Alleen het formaat .JPEG en .GIF
zijn toegelaten </b><br><br>"
End If
Else
FileUploadReport.Text = "<b>Gelieve een foto te selecteren
vooraleer U op de knop 'opladen' klikt</b><br>"
End If
End Sub
Here is my code :
I'm developing a web application where users can upload multiple files to
the website.
I'm using asp.net 2.0 with FileUpload control and can upload 1 image to the
server, but I would like to upload 5 images in total.
Can someone help me in writing a VB.NET part on how I can upload these
multiple files using the FileUpload control?
Dim UploadPath As String = Request.PhysicalApplicationPath + "\images\"
'Before attempting to save the file, verify that the FileUpload
Control contains a file.
If (FileUpload1.HasFile) Then
'Get the name of the file to upload.
Dim fileName As String = FileUpload1.FileName
'Get the extension of the upload file.
Dim extension As String = System.IO.Path.GetExtension(fileName)
'Allow only files with .JPEG or .GIF extensions
If (extension = ".jpeg") Or (extension = ".gif") Then
'Get the size in bytes of the file uploaded.
Dim FileSize As Integer = FileUpload1.PostedFile.ContentLength
'Allow only files less than 5,100,000 bytes (Approximately 5
MB) to be uploaded.
If (FileSize < 800000) Then
'Append the name of the uploaded file to the path.
UploadPath += FileUpload1.FileName
'Call the SaveAs method to save the uploaded file.
FileUpload1.PostedFile.SaveAs(UploadPath)
'Notify the user that the file has been uploaded
successfully.
FileUploadReport.Text = "<b>Bestand is opgeladen naar de
website vanaf: </b><br>" & _
FileUpload1.PostedFile.FileName & _
"Content Type " & FileUpload1.PostedFile.ContentType & _
"Length " & FileUpload1.PostedFile.ContentLength
SqlDataSource1.Insert()
Else
FileUploadReport.Text = "<b>Foto is niet opgeladen omdat
het bestand groter is dan 800K!</b><br>"
End If
Else
'Notify the user why their file was not uploaded.
FileUploadReport.Text = "<b>Bestand is niet opgeslagen, dit
omdat U niet het juiste formaat hebt geselecteerd!</b><br>" + _
"<b>Alleen het formaat .JPEG en .GIF
zijn toegelaten </b><br><br>"
End If
Else
FileUploadReport.Text = "<b>Gelieve een foto te selecteren
vooraleer U op de knop 'opladen' klikt</b><br>"
End If
End Sub
Here is my code :