
06-27-2012, 06:42 AM
|
|
Freshman
|
|
Join Date: Mar 2009
Posts: 31
|
|
Help me Return a String from a Function
|
Hi all!
I am working on this problem 4 hours now an i cant figure the right way out!
I have a class in this class i call a function which should return some string
the class connects to an ftp server and list the directory and returns the filenames of the dir.
Code:
Public Function GetFileList(ByVal host As String, ByVal username As String, ByVal password As String, ByVal currentdirectory As String) As List(Of String)
Dim oFTP As FtpWebRequest = CType(FtpWebRequest.Create(host & currentdirectory), FtpWebRequest)
oFTP.Credentials = New NetworkCredential(username, password)
oFTP.KeepAlive = True
oFTP.Method = WebRequestMethods.Ftp.ListDirectory
Dim response As FtpWebResponse = CType(oFTP.GetResponse, FtpWebResponse)
Dim sr As StreamReader = New StreamReader(response.GetResponseStream)
Dim str As String = sr.ReadLine
Dim oList As New List(Of String)
While str IsNot Nothing
If str.StartsWith(Data) Then
oList.Add(str)
End If
str = sr.ReadLine
End While
sr.Close()
response.Close()
oFTP = Nothing
Return oList
End Function
so this should return all filenames of that directory
like:
Data1.xml
Data2.xml
Data3.xml
Now i have a form with a listview where i want to call this function and get the files of the "olist"
HOW CAN I DO THAT?!?! i mean how would my sub look like on my form where i want to call that function?
|
|