When using WebClient to download files I get "URI Formats are not supported"

Posted on 2007-10-03
Last Modified: 2013-12-17
Here's my code:

WebClient wc = new WebClient ();
wc.DownloadFile ("", "http://localhost/Images/Image.jpg");

I always get this crush when running in Server mode.
I guess I need to change some settings in my IIS to fix that. not sure what.
Question by:Faruz
    1 Comment
    LVL 9

    Accepted Solution

    wc.DownloadFile ("", filename)
    Now the problem is that "filename" is "The name of the local file that is to receive the data."
    "http://localhost/Images/Image.jpg" is not quite a "local file that is to receive the data" but an URI.
    Also if you use that on Server Side via and asp page or a web service, the default path (if you specify only a filename, i.e. "Image.jpg") is the Application.StartupPath that means the virtual directory where your application resides. The problem here is that your web app will restart due the change of the files in the application root or in any subfolders of the app directory.
    Therefore, if you use it on server side, you have to give rights to the user that IIS runs under on a specific directory, other than the virtual directory (let's say c:\\MyImagesFolder) and set the filename fully qualified to that folder("c:\\MyImagesFolder\Image.jpg"). That would do your job.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    761 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

    11 Experts available now in Live!

    Get 1:1 Help Now