Hi. First Post...
Just need some help with this program I'm doing..

I've been programming a FTP Client and i've got the base done but i just have one problem...I've added a listview with 3 columns. 1st column is File Name, 2nd column is File type and the 3rd column is File Modified. The problem is that I've managed to get the file type and file name both come under their relevent column but i just can't get the date modified to work the same. Can some please help me on this. Been working for HOURS.... and still nothing

My Code for that particular page 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
            Dim listviewitem As ListViewItem = New ListViewItem


        End Using
    Catch ex As Exception
    End Try
End Sub
Public Sub LoadFiles()
    Dim ftp As FtpWebRequest = DirectCast(WebRequest.Create(Login.TextBox3.Text), FtpWebRequest)
    ftp.Method = WebRequestMethods.Ftp.ListDirectory
    Dim ftpFiles As New Collection()
    ftp.Credentials = New NetworkCredential(Login.TextBox1.Text, Login.TextBox2.Text)
    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)
        Dim listviewitem As ListViewItem = New ListViewItem
        listviewitem = ListView1.Items.Add(file)
        listviewitem.SubItems.Add(ext)

    Next

    reader.Close()
    responseStream.Close()
    Response.Close()

End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    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 ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.SelectedIndexChanged
    TimeDate()
End Sub

End Class

Thanks.
Ahmed.C

Edited 3 Years Ago by Reverend Jim: typo

You coded

Using response1 = CType(ftp1.GetResponse(), Net.FtpWebResponse)
    dte = response1.LastModified
    Dim listviewitem As ListViewItem = New ListViewItem
End Using

but listviewitem goes out of scope as soon as you leave the Using block so declaring a new instance there is pointless. You then have

Dim listviewitem As ListViewItem = New ListViewItem
listviewitem = ListView1.Items.Add(file)
listviewitem.SubItems.Add(ext)

You don't add the date to the subitems. If you want it to be displayed you have to add it into the list. By the way, a shorter method of adding items is

ListView1.Items.Add(New ListViewItem({fileName,fileExt,fileDate}))

Hi. Thank you soo much for that line of code and yea.. I really need to be organised..but after playing around with the code i've come to a point where I'm not sure where to actually put that ListView1.Items.Add(New ListViewItem({file, ext, dte})). I've tried to put it on my TimeDate and make it load when the files load but that didn't work. And i also tried to make another get ftp request, getdatetimestamp all that in my LoadFile sub but it doesn't seem to work. Is there aything that im missing?

Thanks
Ahmed.C

I can't answer that as I've never used the FTP control. However, I noticed that you said treeview in your original post where I'm sure you meant to say listview. I took the liberty of correcting that.

Yea sorry. It was a listview. But i guess i can thank you for taking your time to help me with this problem. I'm still trying to get it to work but hopefully i will :D

This article has been dead for over six months. Start a new discussion instead.