简体   繁体   中英

How to set a folder as the download location folder

I have a url link that once you click on it, a txt file automatically downloads but I want to set the folder where this txt file downloads to be in the below desktop folder "C:\\Users\\User1\\Desktop\\Folder"

The below link opens the URL in a browser and downloads the file automatically to the "Downloads" folder as I am using Chrome. I would like to set the download folder via sql vb.net.

Below are the queries I tried but only the first one worked but downloaded to "Downloads" folder (very simple):

Private Sub UpdateBtn_Click(sender As Object, e As EventArgs) Handles UpdateBtn.Click

  System.Diagnostics.Process.Start("URL")

End Sub

I also tried the below code but it gave me an error that I have to specify a file name - but I don't want it to work that way:

My.Computer.Network.DownloadFile("URL", "C:\Users\User1\Desktop\Folder", "", "", False, 500, True)

Another query I tested but nothing happened:

Dim wc As New Net.WebClient
Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
wc.DownloadFileAsync(New Uri("URL"), Path)

Any help would be much appreciated.

Thank you all !

Marc

If it's just a text file you could use the WebClient to download it straight from your app and then have your app write it out to the user's hard drive (wherever you have permission of course).

Dim wc As New WebClient()
AddHandler wc.DownloadStringCompleted, AddressOf wc_DownloadStringCompleted   
wc.DownloadStringAsync("URL")

Private Shared Sub wc_DownloadStringCompleted(sender As Object, e As DownloadStringCompletedEventArgs)

'add any error handling code
'...

File.WriteAllText("C:\Users\User1\Desktop\Folder\MyFile.txt", e.Result)

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM