C# ASP.Net抓取外部网站目录的内容并存储在列表框内?
我已经通过使用从我的服务器上的目录中的文件填充列表框来实现了这一点C# ASP.Net抓取外部网站目录的内容并存储在列表框内?,c#,asp.net,vb.net,listbox,uri,C#,Asp.net,Vb.net,Listbox,Uri,我已经通过使用从我的服务器上的目录中的文件填充列表框来实现了这一点 Dim diFiles As DirectoryInfo = New DirectoryInfo(Server.MapPath("~/pdfs/")) 然后使用 lstFiles.DatasSource = diFiles.GetFiles("*.pdf") 最后,使用 For Each fri In lstFiles.DataSource ListBox1.Items.Add(fri.ToString) Next
Dim diFiles As DirectoryInfo = New DirectoryInfo(Server.MapPath("~/pdfs/"))
然后使用
lstFiles.DatasSource = diFiles.GetFiles("*.pdf")
最后,使用
For Each fri In lstFiles.DataSource
ListBox1.Items.Add(fri.ToString)
Next
但是,现在我需要使用外部网站目录执行相同的操作,但是当我尝试通过server.mapPath(“”)输入外部服务器目录时,会出现一个例外,即URI在DirectoryInfo中无效
我试过了
For Each f In Directory.GetFiles("http://example.com/pdfdirectory/") 'put your directory path here
Try
ListBox1.Items.Add(File.ReadAllLines(f)(0)) 'Read the first line of each file
Catch ex As ArgumentNullException
ListBox1.Items.Add("[NO DATA]") 'If no Data catch Error
Catch ex As IndexOutOfRangeException
ListBox1.Items.Add("[NO DATA]") 'If no Data catch Error
End Try
Next
然而,上面也给了我一个URI异常
我最后尝试的是WebRequest,但我不知道如何将目录放入列表框
Dim request = DirectCast(WebRequest.Create("http://www.example.com/pdfdirectory/"), HttpWebRequest)
Dim response = DirectCast(request.GetResponse(), HttpWebResponse)
Using reader = New StreamReader(response.GetResponseStream())
Dim body As String = reader.ReadToEnd()
End Using
我不想先下载这些文件。我只希望列表框文本是外部服务器上文件名的一部分
我应该提到的是,服务器已经有了可以查看的目录文件。带有PDF列表的/PDF目录索引我怀疑您是否可以,这将是一个巨大的安全问题。您只能访问本地服务器的文件系统machine@zgood我应该提到的是,服务器已经有了可以查看的目录文件。带有PDF列表的/pdfdirectory索引这是否位于您的本地网络内?@F0r3v3r-A-N00b否,这就是为什么我想要一个可以使用URI的解决方案