Solved

How do I download images using WebClient?

Posted on 2008-10-15
1
459 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

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.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
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…

726 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