using (var client = new WebClient())
{
client.DownloadFile("http://example.com/file/song/a.mpeg", "a.mpeg");
}
public static bool DownloadImage(string imageUrl, string filename, ImageFormat format)
{
WebClient client = new WebClient();
Stream stream = client.OpenRead(imageUrl);
Bitmap bitmap;
bitmap = new Bitmap(stream);
if(bitmap != null)
bitmap.Save(filename, format);
stream.Flush();
stream.Close();
client.Dispose();
return File.Exists(filename);
}
using System;
using System.Net;
using System.IO;
class FileDownloader
{
static void Main()
{
string path = "http://www.educative.io/cdn-cgi/image/f=auto,fit=contain,w=2400/api/edpresso/shot/5224207262154752/image/5022165490991104.png";
using(WebClient client = new WebClient())
{
client.DownloadFile(path,"image.png");
}
if(File.Exists("image.png"))
{
Console.WriteLine("File Downloaded Successfully");
}
else
{
Console.WriteLine("Not able to download the file.");
}
}
}