Ahmed.C 0 Junior Poster in Training

So I've been working on this simple FTP Client and i've come across this problem. Basically when the user clicks on the folder, a label changes saying ftpserver.com/folder1 and then when a user clicks on the folder inside that it's meant to be ftpserver.com/folder1/folder2 but the label is only saying ftpserver.com/folder2. Can someone please help me.
The Code is:

Imports System.Net
Imports System.IO
Public Class MainMenu
    Private Sub MainMenu_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        LoadFiles()
        Timer1.Start()

    End Sub
    Public Sub TimeDate()
        Try
            Dim ftp1 As Net.FtpWebRequest = Net.FtpWebRequest.Create(Login.TextBox3.Text & ListView1.SelectedItems(0).Text)
            ftp1.Credentials = New NetworkCredential(Login.TextBox1.Text, Login.TextBox2.Text)
            ftp1.Method = Net.WebRequestMethods.Ftp.GetDateTimestamp
            Dim dte As DateTime
            Using response1 = CType(ftp1.GetResponse(), Net.FtpWebResponse)

                dte = response1.LastModified
                ListView1.Items.Add(New ListViewItem({dte}))
            End Using

        Catch ex As Exception
        End Try
    End Sub
    Public Sub LoadFiles()
        Try

            Dim ftp As FtpWebRequest = DirectCast(WebRequest.Create(Login.TextBox3.Text), FtpWebRequest)
            ftp.Credentials = New NetworkCredential(Login.TextBox1.Text, Login.TextBox2.Text)
            ftp.Method = WebRequestMethods.Ftp.ListDirectory
            Dim ftpFiles As New Collection
            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)
            End While

            For Each file In ftpFiles
                Dim ext As String = IO.Path.GetExtension(file)
                ListView1.Items.Add(New ListViewItem({file, ext}))
                ListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)
            Next




            reader.Close()
            responseStream.Close()
            Response.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick



        LogOutToolStripMenuItem.Text = "Log Out User: " & Login.TextBox1.Text
        For Each lvi In ListView1.Items
            Dim masterItem = From i In ListView1.Items.OfType(Of ListViewItem)()
                             Where i.Text = "."
            Dim masterItem1 = From i In ListView1.Items.OfType(Of ListViewItem)()
            Where i.Text = ".."

            If masterItem.Any Then
                ListView1.Items.Remove(masterItem.First)
                ListView1.Items.Remove(masterItem1.First)
            End If


        Next
    End Sub
    Private Sub GoToFTPServerToolStripMenuItem_Click(sender As Object, e As EventArgs)
        Process.Start(Login.TextBox3.Text)
    End Sub

    Private Sub FileOptionsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles FileOptionsToolStripMenuItem.Click
        Application.ExitThread()
        Application.Exit()

    End Sub

    Private Sub LogOutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LogOutToolStripMenuItem.Click


        Me.Close()
        Login.Show()
        MsgBox("Successfully logged out from " & Login.TextBox1.Text, MsgBoxStyle.Information, "Logged Out")
        Login.TextBox2.Clear()

    End Sub

    Private Sub MainMenu_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
        Login.Show()

    End Sub
    Private Sub ToolStripDropDownButton1_Click(sender As Object, e As EventArgs) Handles ToolStripDropDownButton1.Click
        Try
            ListView1.Items.Clear()
            Dim ftp As FtpWebRequest = DirectCast(WebRequest.Create(Login.TextBox3.Text), FtpWebRequest)
            ftp.Credentials = New NetworkCredential(Login.TextBox1.Text, Login.TextBox2.Text)
            ftp.Method = WebRequestMethods.Ftp.ListDirectory
            Dim ftpFiles As New Collection
            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)
            End While

            For Each file In ftpFiles

                Dim ext As String = IO.Path.GetExtension(file)
                ListView1.Items.Add(New ListViewItem({file, ext}))
            Next
            reader.Close()
            responseStream.Close()
            Response.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub ToolStripSplitButton2_ButtonClick(sender As Object, e As EventArgs) Handles ToolStripSplitButton2.ButtonClick
        Try

            Dim ftp As FtpWebRequest = DirectCast(WebRequest.Create(Label1.Text & "/"), FtpWebRequest)
            ftp.Credentials = New NetworkCredential(Login.TextBox1.Text, Login.TextBox2.Text)
            ftp.Method = WebRequestMethods.Ftp.ListDirectory
            Dim ftpFiles As New Collection
            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)
            End While
            ListView1.Items.Clear()
            For Each file In ftpFiles


                Dim ext As String = IO.Path.GetExtension(file)
                ListView1.Items.Add(New ListViewItem({file, ext}))
            Next
            reader.Close()
            responseStream.Close()
            Response.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub BackToolStripMenuItem_Click(sender As Object, e As EventArgs)
        Try
            Dim ftp As FtpWebRequest = DirectCast(WebRequest.Create(Login.TextBox3.Text), FtpWebRequest)
            ftp.Credentials = New NetworkCredential(Login.TextBox1.Text, Login.TextBox2.Text)
            ftp.Method = WebRequestMethods.Ftp.ListDirectory
            Dim ftpFiles As New Collection
            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)
            End While

            For Each file In ftpFiles
                ListView1.Items.Clear()

                Dim ext As String = IO.Path.GetExtension(file)
                ListView1.Items.Add(New ListViewItem({file, ext}))
            Next
            reader.Close()
            responseStream.Close()
            Response.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.SelectedIndexChanged
        Try
            Label1.Text = Login.TextBox3.Text & ListView1.FocusedItem.Text
        Catch ex As Exception

        End Try
    End Sub
    Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Dim myString As String = Label1.Text
        While myString.IndexOf(" ") <> -1
            myString = myString.Replace(" ", "%20")
        End While
        Label1.Text = myString
    End Sub
End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.