Response.ContentType = "image/jpeg";
Response.AppendHeader("Content-Disposition","attachment; filename=SailBig.jpg");
Response.TransmitFile( Server.MapPath("~/images/sailbig.jpg") );
Response.End();
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
protected void Page_Load(object sender, EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
string link = "http://localhost:1700/ImageAdminPortal/ImageDataDownload.aspx";
//I get the link from the querystring here - that code has been left out
if (link != null)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
byte[] _data;
_data = this.LoadFromURL(link);
FileStream fs = new FileStream("c:/newImage.jpg", FileMode.OpenOrCreate, FileAccess.ReadWrite);
fs.Write(_data, 0, _data.Length);
fs.Close();
}
}
protected byte[] LoadFromURL(string url)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
// create a request for the URL
WebRequest wr = WebRequest.Create(url);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
byte[] result;
byte[] buffer = new byte[4096];
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// get the response and buffer
using (WebResponse response = wr.GetResponse())
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
using (Stream responseStream = response.GetResponseStream())
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
using (MemoryStream memoryStream = new MemoryStream())
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
int count = 0;
do
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
count = responseStream.Read(buffer, 0, buffer.Length);
memoryStream.Write(buffer, 0, count);
} while (count != 0);
result = memoryStream.ToArray();
}
}
}
return result;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}