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
这是我的代码而且没有用。错误是“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
”。
我该怎么做?谢谢!
答案 0 :(得分:2)
要解决您提出的错误,只需将Function
更改为Sub
即可。
但是,执行此操作后,您的代码仍然无效。您将遇到新错误,因为 System.IO目录和文件类仅适用于本地文件系统。您不能以这种方式引用远程https位置。您需要使用System.Net.HttpWebRequest / System.Net.HttpWebResponse或System.Net.WebClient,这意味着基本上从头开始使用此代码。
一个非常简单的示例,可能有效,也可能不行,具体取决于https要求:
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