ASP.NET 实现通过URL 获取远程的图片或者文件方法。我们可以创建System.Net.WebClient 对象 通过 DownloadFile() 方法来获取远程图片或者文件 。 具体实现如下
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default7 : System.Web.UI.Page
...{
protected void Page_Load(object sender, EventArgs e)
...{
string sRmFile = "http://zi.youkuaiyun.com/1000huawei.gif";
string sSavePath = "c:/1000huawei.gif";
System.Net.WebClient wc = new System.Net.WebClient();
try
...{
wc.DownloadFile(sRmFile, sSavePath);
Response.Write("远程文件已经下载完毕!");
}
catch (System.Exception ex)
...{
Response.Write("error:" + ex.Message.ToString());
}
}
}
本文介绍了一种使用ASP.NET通过URL下载远程图片的方法。通过创建System.Net.WebClient对象并调用DownloadFile()方法来实现远程文件的下载。该方法简单易行。
350

被折叠的 条评论
为什么被折叠?



