954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to download files in listbox

I have tried many ways to download the files in a listbox. non-seems to work.

the listbox has url
eg:
<a href="http://www.hahaww.com/2.pdf">http://www.hahaww.com/2.pdf</a>
<a href="http://www.hahaww.com/f1.pdf">http://www.hahaww.com/f1.pdf</a>
<a href="http://www.hahaww.com/24.pdf">http://www.hahaww.com/24.pdf</a>

I want to download the files until ListBox.Items.Count = 0 which each file with number ording...
for eg:
2.pdf will be 1.pdf
f1.pdf will be 2.pdf
24.pdf will be 3.pdf

and so on until ListBox.Items.Count = 0
all files will be downloaded until ListBox.Items.Count = 0

to download i have used

My.Computer.Network.DownloadFile(ListBox1.SelectedItem, "c:\temp\1.pdf")


i also couldnt find a way to increase the numbering...

linezero
Newbie Poster
17 posts since Nov 2010
Reputation Points: 11
Solved Threads: 0
 

See if this helps to download all web files from a ListBox.

Dim myFolder As String = "C:\" '// folder to save files to.
        Dim sFileExtension As String = Nothing '// string to get the file extension from web file.
        Dim iFileNameNumber As Integer = 0 '// used to save file names as #'s.
        For Each itm As String In ListBox1.Items '// loop thru all items.
            sFileExtension = itm.Substring(itm.LastIndexOf("."c)) '// get file .Extension from web file path of ListBox item.
            iFileNameNumber += 1 '// increment for FileName.
            My.Computer.Network.DownloadFile(itm, myFolder & iFileNameNumber & sFileExtension) '// Download file.
        Next
        MsgBox("Files Download Successful.")
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

I get an error saying "Conversion from type 'Match' to type 'String' is not valid."
at

For Each itm As String In ListBox1.Items
linezero
Newbie Poster
17 posts since Nov 2010
Reputation Points: 11
Solved Threads: 0
 

Can you post the entire For/Next loop code and specify which line is giving you the finger, I mean "error".:D

codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: