Hi,
As an example....
You may have a separate aspx file and at it's page load event have this code..
protected void Page_Load(object sender, EventArgs e)
{
string path = Request.QueryString["image_path"];
Response.ContentType = "image/jpg";
WebRequest objReq = WebRequest.Create(path);
WebResponse objResp = objReq.GetResponse();
Stream objStream = objResp.GetResponseStream();
int length = (int)objResp.ContentLength;
BinaryReader reader = new BinaryReader(objStream, Encoding.ASCII);
byte[] bytes = reader.ReadBytes((int)length);
Response.OutputStream.Write(bytes, 0, length);
reader.Close();
objStream.Close();
}
you need to use these additional namespaces in that page...
<pre lang="cs">using System.IO;
using System.Net;
using System.Text;
In your main aspx file have an image and a button
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:Image ID="Image1" runat="server" ImageUrl="" />
on the button click event
protected void Button1_Click(object sender, EventArgs e)
{
Image1.ImageUrl = "~/image.aspx?image_path=http://www.a1indiaflowers.in/wp-content/uploads/2010/12/47-150x150.jpg";
}
This example you can extend to gridview row bound event. This loads the image dynamically. But as Sandeep said you can have a local cache of those images and have that image list in a database. So that you can check the image availability and if available load from local.
To download to local you can get the response stream in the above example and use a file stream to save it on the server..
StreamReader reader = new StreamReader(objStream,Encoding.ASCII);
FileStream fStream = new FileStream("Test.jpg", FileMode.Create);
StreamWriter writer=new StreamWriter(fStream);
writer.Write(reader.ReadToEnd());
objStream.Close();
reader.Close();
writer.Close();
fStream.Close();