Http file download & Keeping original file name. How?

Posted on 2006-06-02
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 = ""
       sLocalFile = "c:\Temp\file.txt"

       client.DownloadFile(sSourceUrl, sLocalFile)

Thanks for anything.

Question by:donniedarko801
    LVL 96

    Accepted Solution

    Maybe something like this:

           Dim sSourceUrl As String = ""
           Dim sLocalFile As String = "c:\Temp\" & IO.Path.GetFileName(sSourceURLfile)

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

    LVL 1

    Author Comment

    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

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now