Pat
Pat

Reputation: 63

Visual Basic DownloadFile won't overwrite

I'm attempting to download a file from a website using visual basic using the following code, but I keep getting the accept overwrite dialog box. Is there a way to keep Windows from presenting the overwrite file dialog? I'm not sure why this is happening because I changed the default overwrite to true.

My.Computer.Network.DownloadFile(
            "http://example.com",
            "C:\download_location",
            userName:=String.Empty,
            password:=String.Empty,
            showUI:=False,
            connectionTimeout:=100000,
            overwrite:=True)

Upvotes: 1

Views: 286

Answers (1)

miroxlav
miroxlav

Reputation: 12194

Related MSDN article says:

showUI
    Boolean. Specifies whether to display the progress of the operation. Default is False.

This one (and any other descriptions found there) set no expectations about suppressing dialog box for overwriting the file.

So as Vinay Pandey suggested, to disable the dialog box with question, delete the file beforehand by yourself. This brings also one significant advantage: if existing file has any problems (insufficient permissions, pending file locks) if forces you (as programmer) to deal with them before download is started. I mean, it is always better to handle these things by yourself than to rely on some black-box action.

If IO.File.Exists(exampleName) Then IO.File.Delete(exampleName) ' plus error handling

...and also mind the case if there already is a directory with that file name (e.g. directory called file.txt).

Upvotes: 1

Related Questions