Function getItems()
''# make a reference to a directory
Dim di As New IO.DirectoryInfo("https://ipossum.svn.sourceforge.net/svnroot/ipossum/")
Dim diar1 As IO.FileInfo() =开发者_如何学编程 di.GetFiles()
Dim dra As IO.FileInfo
''#list the names of all files in the specified directory
For Each dra In diar1
ListBox1.Items.Add(dra)
Next
End Function
That is my code and it did not work. The error was "Warning 1 Function 'getItems' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used. C:\Users\******\AppData\Local\Temporary Projects\iPossum\Form1.vb 13 5 iPossum
".
How do I do this? Thanks!
To fix the error you're asking about, just change the word Function
to Sub
.
However, after you do this you're code still won't work. You'll have a new error, because the System.IO directory and file classes only work on the local file system. You can't reference a remote https location that way. You'll need to use System.Net.HttpWebRequest/System.Net.HttpWebResponse or System.Net.WebClient instead, and that means essentially starting from scratch with this code.
A very simple example that may or may not work, depending on the https requirement:
Dim fileList As String
Using wc As New WebClient
fileList = wc.DownloadString("https://ipossum.svn.sourceforge.net/svnroot/ipossum/")
End Using
''# Here you'll have to parse the file names out of this response on your own
精彩评论