Http file download & Keeping original file name. How?

Posted on 2006-06-02
Medium Priority
Last Modified: 2012-06-27
Hello experts,

I have this small piece of code and it works great except I have to hard code the local file name. Is there a way to save downloaded file with original file name?

       Dim sSourceUrl As String    ' File to download with URL
       Dim sLocalFile As String    ' File to crate on the local system
       Dim client As New WebClient

       sSourceUrl = "http://www.download.com/file.txt"
       sLocalFile = "c:\Temp\file.txt"

       client.DownloadFile(sSourceUrl, sLocalFile)

Thanks for anything.

Question by:donniedarko801
LVL 96

Accepted Solution

Bob Learned earned 1000 total points
ID: 16820685
Maybe something like this:

       Dim sSourceUrl As String = "http://www.download.com/file.txt"
       Dim sLocalFile As String = "c:\Temp\" & IO.Path.GetFileName(sSourceURLfile)

       Dim client As New WebClient
       client.DownloadFile(sSourceUrl, sLocalFile)


Author Comment

ID: 16820824
Thanks a lot!

Just out of curiosity, how would you download an http folder and all files within from a website?

I'll be happy to start another question if need be.

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question