System.Drawing.Image image = null;
try
{
string fileName = imgs[i];
string filePath = commonpath + imgs[i];
string localFile = localpath + imgs[i];
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(filePath);
HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
if (webresponse.StatusCode == HttpStatusCode.OK)
{
image = System.Drawing.Image.FromStream(webresponse.GetResponseStream());
//保存在服務器的本地硬盤
image.Save(localFile);
//保存在客戶端上
File.WriteAllBytes(@"D:\1.JPG",byteImage);
}
}
catch (Exception ex)
{
string result = "遠程圖片保存失敗,原因為:\n" + ex.Message;
Response.Write(result);
Response.End();
break;
}
finally
{
if (image != null)
{
image.Dispose(); //釋放資源
}
}
摘自 小白白小