Hi, today I will demonstrate you how to download / pull image from another website.
For this it is required for use below namespace :
Now for c# part
that's all.
Two thing too keep in mind.
1) imageURL : apply image url which you want to download.
2) FolderAndFile_NameToDownload : apply FolderName with FileName where you want to download that image in your website.
Above code can be apply fro Website as wall as Windows Form application.
For this it is required for use below namespace :
using System.Net;
using System.IO;
Now for c# part
private void DownloadImage(string imageURL, string FolderAndFile_NameToDownload)
{
HttpWebRequest lxRequest = (HttpWebRequest)WebRequest.Create(imageURL);
String lsResponse = string.Empty;
using (HttpWebResponse lxResponse = (HttpWebResponse)lxRequest.GetResponse())
{
using (BinaryReader reader = new BinaryReader(lxResponse.GetResponseStream()))
{
Byte[] lnByte = reader.ReadBytes(1 * 1024 * 1024 * 10); //Buffer
using (FileStream lxFS = new FileStream(Server.MapPath(FolderAndFile_NameToDownload), FileMode.Create))
{
lxFS.Write(lnByte, 0, lnByte.Length);
}
}
}
}
that's all.
Two thing too keep in mind.
1) imageURL : apply image url which you want to download.
2) FolderAndFile_NameToDownload : apply FolderName with FileName where you want to download that image in your website.
Above code can be apply fro Website as wall as Windows Form application.
0 comments :
Post a Comment