[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2309
  • Last Modified:

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

Here's my code:

WebClient wc = new WebClient ();
wc.DownloadFile ("http://ia.media-imdb.com/media/imdb/01/I/11/23/10/10m.jpg", "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.
0
Faruz
Asked:
Faruz
1 Solution
 
ripahoratiuCommented:
First
wc.DownloadFile ("http://ia.media-imdb.com/media/imdb/01/I/11/23/10/10m.jpg", 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.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now