有谁知道如何在VB.Net中解析Webclient.DowloadFile到File? 我目前正在使用以下代码,但我不断收到错误: (BC30491)表达式不会产生值。 (BC30311)类型的值无法转换为文件
Private Function DepartmentDataDownloader() As String
Dim webClient As New System.Net.WebClient
'I get here the error BC30491
Dim result As File = webClient.DownloadFile("https://intern.hethoutsemeer.nl/index2.php?option=com_webservices&controller=csv&method=hours.board.fetch&key=F2mKaXYGzbjMA4V&element=departments", "intern.hethoutsemeer.nl.1505213278-Departments.csv")
If webClient IsNot Nothing Then
'and here BC30311
Dim result As File = webClient
UploaderFromDownload(webClient)
End If
Return ""
End Function
答案 0 :(得分:1)
DownloadFile
方法没有返回值,因为DownloadFile
是Sub
。这就是您收到BC30491
错误的原因。第二个参数指定本地文件的路径(以及下载结果)。
所以你可以尝试以下内容:
Dim webClient As New System.Net.WebClient
'after this the file specified on second parameter should exists.
webClient.DownloadFile("https://intern.hethoutsemeer.nl/index2.php?option=com_webservices&controller=csv&method=hours.board.fetch&key=F2mKaXYGzbjMA4V&element=departments", "intern.hethoutsemeer.nl.1505213278-Departments.csv")
If webClient IsNot Nothing Then
'do something with the downloaded file (File.OpenRead(), File.*).
'Dim result As File
UploaderFromDownload(webClient)
End If
您还尝试将WebClient
值分配给File
变量。这是不可能的,因此您会收到BC30311
错误。
提示:您无法创建
File
类的实例。File
类提供用于创建,复制,删除,移动和打开单个文件的静态方法,并帮助创建FileStream
个对象。
来源: https://docs.microsoft.com/en-us/dotnet/api/system.io.file