Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
4.67/5 (2 votes)
See more:
Hello everyone

i am using the following code to fetch image through WebClient

C#
WebClient wc = new WebClient();
           byte[] bytes = wc.DownloadData("http://xyz.com/Image/1.jpg");
           MemoryStream ms = new MemoryStream(bytes);
           var image = System.Drawing.Image.FromStream(ms);


that is working fine but i want to save the WebClient downloaded file into to my project folder. how to achieve this.

Thanks
Posted

User image.Save(filePath)?

For your project folder...do you mean application folder or your developer project?

Application folder:
System.Reflection.Assembly.GetExecutingAssembly().CodeBase

your developer project you'll have to put in config file or otherwise save it in some application settings.
 
Share this answer
 
C#
WebClient wc = new WebClient();
byte[] bytes = wc.DownloadData("http://xyz.com/Image/1.jpg");
System.IO.File.WriteAllBytes("your_path+your_filename+fileextention", bytes);
 
Share this answer
 
Comments
@p@richit 18-Sep-14 6:29am    
thanks for reply @raju . if my filepath is also a url ("http://225.162.10.162:81/ImagesFile/") then it will worked or not ?
raju melveetilpurayil 18-Sep-14 6:36am    
If the location is not local, then you want to upload file
@p@richit 18-Sep-14 6:37am    
have u any idea about that , how to upload it ?
raju melveetilpurayil 18-Sep-14 7:03am    
you can check this for a sample.. http://chiragvidani.blogspot.co.uk/2011/10/how-to-uploaddownload-file-tofrom.html

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900