Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am successfully downloading a zipped CSV file from the web. I am also able to unzip it and save it to a CSV file and then parse it to a much smaller text file. I want to rewrite all three files each time I down load. I insert the date as you can see in the File name because the filename contains the daily date. Because the file changes daily, I want to use the latest version. Here is my code.

Try
            My.Computer.Network.DownloadFile(URL, "C:\Ra\List\ValidList" & myDate & ".zip", "", "", False, 1000, True)

        Catch
            MsgBox("You may not be connected to the Internet, Connect and try again")
            Exit Sub
        End Try
        Try
            Dim zipPath As String = "C:\Ra\List\ValidList" & myDate & ".zip"
            Dim extractPath As String = "C:\Ra\List"
            ZipFile.ExtractToDirectory(zipPath, extractPath)
        Catch ex As Exception
            MsgBox("The File may already exist...continue.")
        End Try


I could delete all three files before downloading but I think I can overwrite each which I would prefer.

What I have tried:

I have tried changing the last three parameters in the My.Computer.Network.Download(URL, Save to filename, Parameter 1, Time parameter, Parameter 2) But MSDN does not say which parameter is which...i.e., view download progress or overwrite file, and when testing I get inconsistent results.
Posted
Updated 23-Jan-19 1:49am
Comments
CHill60 23-Jan-19 2:25am    
"MSDN" does not say which parameter is which... I've never seen that before. Share the url of the documentation

1 solution

Quote:
I have tried changing the last three parameters in the My.Computer.Network.Download(URL, Save to filename, Parameter 1, Time parameter, Parameter 2) But MSDN does not say which parameter is which...i.e., view download progress or overwrite file, and when testing I get inconsistent results.


MSDN documentation is available here: Network.DownloadFile Method (Microsoft.VisualBasic.Devices) | Microsoft Docs[^]

Once the download is finished you can extract files into directory, provide several operations on them and zip'em again. See: ZipFile Class (System.IO.Compression) | Microsoft Docs[^]. There you'll find examples.

As to the download method, i'd recommend to use: WebClient.DownloadFile Method (System.Net) | Microsoft Docs[^] and even better WebClient.DownloadFileAsync Method (System.Net) | Microsoft Docs[^] , because they are more suitable.
You can check the progress of downloading, by using:
WebClient.OnDownloadProgressChanged(DownloadProgressChangedEventArgs) Method (System.Net) | Microsoft Docs[^]
WebClient.OnDownloadFileCompleted(AsyncCompletedEventArgs) Method (System.Net) | Microsoft Docs[^]

If you would like to upload back data into server, use: WebClient.UploadFile Method (System.Net) | Microsoft Docs[^] or WebClient.UploadFileAsync Method (System.Net) | Microsoft Docs[^]

Good luck!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900