1

Does anyone know how to parse a Webclient.DowloadFile to File in VB.Net? I'm currently using the following Code but I keep getting the errors: (BC30491) Expression does not produce a value. (BC30311) Value of Type can not be converted to File

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
Alpha Coding
  • 37
  • 1
  • 2
  • 13
  • The func [`DownloadFile`](https://msdn.microsoft.com/en-us/library/ez801hhe(v=vs.110).aspx) will not return value. And you can init `File` with the path you store the downloaded file – Prisoner Sep 13 '17 at 07:31

1 Answers1

1

The DownloadFile method doesn't return a value, because DownloadFile is a Sub. This is the reason why you get the BC30491 error. The second parameter specifies the path of the local file (and the result of the download).

So you can try something like the following:

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

You also try to assign the WebClient value to a File variable. This is not possible so you get the BC30311 error.

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://learn.microsoft.com/en-us/dotnet/api/system.io.file

Sebastian Brosch
  • 42,106
  • 15
  • 72
  • 87