WebClient.DownloadFile 转换为文件 VB.NET
WebClient.DownloadFile convert to File VB.NET
有谁知道如何将 Webclient.DowloadFile 解析为 VB.Net 中的文件?
我目前正在使用以下代码,但我不断收到错误消息:
(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
DownloadFile
method doesn't return a value, because DownloadFile
is a Sub
. This is the reason why you get the 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
错误。
Hint: You can't create an instance of the File
class. The File
class provides static methods for the creation, copying, deletion, moving, and opening of a single file, and aids in the creation of FileStream
objects.
source: https://docs.microsoft.com/en-us/dotnet/api/system.io.file
有谁知道如何将 Webclient.DowloadFile 解析为 VB.Net 中的文件? 我目前正在使用以下代码,但我不断收到错误消息: (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
DownloadFile
method doesn't return a value, because DownloadFile
is a Sub
. This is the reason why you get the 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
错误。
Hint: You can't create an instance of the
File
class. TheFile
class provides static methods for the creation, copying, deletion, moving, and opening of a single file, and aids in the creation ofFileStream
objects.
source: https://docs.microsoft.com/en-us/dotnet/api/system.io.file