0

Hello,

I am attempting to put a list box in to my program, so that when the page loads, a list of files from my FTP site appear.

I also want it so that a file can be selected on the screen and downloaded.

Is there a way to do this?

If so, what sort of listbox should I be looking at? Because the only ones I have come across only connect to Access or SQL Server databases.

Please help...

Thanks,

Dan

3
Contributors
5
Replies
10
Views
6 Years
Discussion Span
Last Post by codereflex
0

Thank you for your message stbuchok.

Ive now got it so the list of FTP files are appearing on the screen and I am now able to select a file from the list and download it.

The problem I have now is that when I load the page, instead of each file only appearing in the list once, each file appears multiple times.

Below is the code that I am using:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
                Dim ftp As FtpWebRequest = DirectCast(WebRequest.Create("ftp://xx.x.xx.xx/In/"), FtpWebRequest)
                
                ftp.Method = WebRequestMethods.Ftp.ListDirectory
                
                Dim ftpFiles As New ArrayList()
                
                ftp.Credentials = New NetworkCredential("user", "password")
                
                Dim Response As FtpWebResponse = ftp.GetResponse()
 
                Dim responseStream As Stream = Response.GetResponseStream()
 
                Dim reader = New StreamReader(responseStream)
                
                While Not (reader.EndOfStream)
                    
                    ftpFiles.Add(reader.ReadLine())
                    
                    'ListBox1.Items.Add(ftpFiles.ToString())
                    
                    For Each file In ftpFiles
                        
                        ListBox1.Items.Add(file)
                        
                    Next

                End While
                
                reader.Close()
 
                responseStream.Close()
 
                Response.Close()

            End Sub

I want it so that each file only appears once in the list.

All help and advice will be greatly appreciated.

Thanks,

Dan

0

Move the For Each loop after the While loop.

While Not (reader.EndOfStream)
 
                    ftpFiles.Add(reader.ReadLine())
 
                    'ListBox1.Items.Add(ftpFiles.ToString())
 
                End While

                For Each file In ftpFiles
 
                    ListBox1.Items.Add(file)
 
                Next
0

Hi stbuchok,

Thank you very much!!!

It works perfectly.

Much appreciated.

Dan

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.