Solved

How do I download images using WebClient?

Posted on 2008-10-15
1
458 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET data base connection 35 90
EF5: Update Model from Database not working 3 76
Make borderless form movable by user 2 25
wordpress theme 8 39
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

739 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