Solved

How do I download images using WebClient?

Posted on 2008-10-15
1
452 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
Comment Utility
Line
wr.Write(image.Length);
changed to
wr.Write(image, 0, image.Length)
Fixed the problem.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
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…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

762 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

8 Experts available now in Live!

Get 1:1 Help Now