Solved

How do I download images using WebClient?

Posted on 2008-10-15
1
456 Views
Last Modified: 2013-12-20
I used the following code to iterate an array of URI based image locations to download the image files to my local drive so I could use them in System.Net.Mail as embedded images. The files on my local drive aren't the image files, they're just small binary stubs. I cribbed this code from a bunch of sources without really understanding in detail what I'm doing. The IMGS array contains (0) the URI , (1) the generated CID for embedding and (3) the local file path/name. Any help is greatly appreciated:

            WebClient wc = new WebClient();
            for (int i=0; i<=ct; i++)
            {
                byte[] image = wc.DownloadData(imgs[i,0]);
                string LocalFile = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), imgs[i,1].ToString().Substring(4,imgs[i,1].ToString().Length-4));
                BinaryWriter wr = new BinaryWriter(File.Open(LocalFile, FileMode.Create));
                wr.Write(image.Length);
                wr.Close();
                imgs[i, 2] = LocalFile;
            }
0
Comment
Question by:rschaeferhig
1 Comment
 

Accepted Solution

by:
rschaeferhig earned 0 total points
ID: 22721858
Line
wr.Write(image.Length);
changed to
wr.Write(image, 0, image.Length)
Fixed the problem.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

789 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