Loop thorough values of a ListBox
-
I have some files listed on a listbox and want to upload them to the server. The values doesn't need to be selected. But I can't even get it working. Below is my source code: Protected Sub uploadButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uploadButton.Click If (foundFilesList.Items.Count > 0) Then Dim _fileUpload As New FileUpload() For i As Integer = 0 To foundFilesList.Items.Count - 1 _fileUpload.SaveAs("~\InputFiles\" & foundFilesList.Items(i).ToString()) Next messageLabel.Text = "The displayed files has been uploaded." Else messageLabel.Text = "No file path has been specified." End If End Sub Where is the bug in the code above? I appreciate you usual support. Thanks.
-
I have some files listed on a listbox and want to upload them to the server. The values doesn't need to be selected. But I can't even get it working. Below is my source code: Protected Sub uploadButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uploadButton.Click If (foundFilesList.Items.Count > 0) Then Dim _fileUpload As New FileUpload() For i As Integer = 0 To foundFilesList.Items.Count - 1 _fileUpload.SaveAs("~\InputFiles\" & foundFilesList.Items(i).ToString()) Next messageLabel.Text = "The displayed files has been uploaded." Else messageLabel.Text = "No file path has been specified." End If End Sub Where is the bug in the code above? I appreciate you usual support. Thanks.
The path
"~\InputFiles\" & foundFilesList.Items(i).ToString())
would refer to the"_application root_\InputFiles"
on the server. Why would you want to upload from the server to the server?? HTH! -
The path
"~\InputFiles\" & foundFilesList.Items(i).ToString())
would refer to the"_application root_\InputFiles"
on the server. Why would you want to upload from the server to the server?? HTH!Thanks Mani, The path "~\InputFiles\" & foundFilesList.Items(i).ToString() is my server/application path where I want to save the files displayed on the listbox (foundFilesList ). Since the file names have been on the foundFilesList(listbox). Do you understand what I am trying to do?
-
Thanks Mani, The path "~\InputFiles\" & foundFilesList.Items(i).ToString() is my server/application path where I want to save the files displayed on the listbox (foundFilesList ). Since the file names have been on the foundFilesList(listbox). Do you understand what I am trying to do?
I'm afraid you cannot do it this way. The source file name is a readonly property on the file upload control and can be set only from the client. You cannot set it in server code and try and start the upload from the server. Only the client browser has to initialize the upload.