2010-08-04 78 views
0
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」。從SourceForge SVN項目獲取文件夾中的項目

我該怎麼做?謝謝!

回答

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 
+0

我不要求任何類型的文件,如果你能很大,並有你能不能給我寫短片? – 2010-08-04 21:32:51

相關問題