本文给大家分享的是实现这样一个功能,想将远程服务器的图片下载到本地主机,图片的名称就是数据库的一个字段,图片不是以二进制的形式存储在数据库的,数据库存储的
来源gao!%daima.com搞$代*!码网
只是图片的名词。
C#实现把图片下载到服务器代码
ASPX页面代码:
<title>根据网址把图片下载到服务器</title> <div> 图片网址:<br /><br /><br /><br /></div>
cs页面代码:
using System; namespace HoverTreeMobile { public partial class GetPictureByUrl : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnImg_Click(object sender, EventArgs e) { try { System.Net.WebClient m_hvtWebClient = new System.Net.WebClient(); string m_keleyiPicture = Server.MapPath("/hovertreeimages/keleyi.jpg-600"); //根据网址下载文件 m_hvtWebClient.DownloadFile(textBoxImgUrl.Text, m_keleyiPicture); hvtImg.ImageUrl = "/hovertreeimages/keleyi.jpg-600"; ltlTips.Text = string.Empty; } catch(Exception ex) { ltlTips.Text = ex.ToString(); } } } }
另外给大家分享一下下载图片的核心方法的思路
using System.Net; WebClient myclient = new WebClient(); myclient.DownloadFile("http://www.baidu.com/img/sslm_logo.gif",@"c:\baidu.gif"); DownloadFile方法里的address就是你要拼成的远程服务器上的URL.
好了,小伙伴们是否有了新的认识了呢,希望大家能够喜欢。
以上就是C#实现把图片下载到服务器代码的详细内容,更多请关注gaodaima搞代码网其它相关文章!