C#实现把图片下载到服务器代码
ASPX页面代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GetPictureByUrl.aspx.cs" Inherits="HoverTreeMobile.GetPictureByUrl" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>根据网址把图片下载到服务器</title> </head> <body> <form id="form1" runat="server"> <div> 图片网址:<br /><asp:TextBox runat="server" ID="textBoxImgUrl" Width="500" Text="/hvtimg/201508/cnvkv745.jpg" /> <br /> <asp:Button runat="server" ID="btnImg" Text="下载" OnClick="btnImg_Click" /> <br /><asp:Image runat="server" ID="hvtImg" /> <br /> <asp:Literal runat="server" ID="ltlTips" /> </div> </form> </body> </html>
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"); //根据网址下载文件 m_hvtWebClient.DownloadFile(textBoxImgUrl.Text, m_keleyiPicture); hvtImg.ImageUrl = "/hovertreeimages/keleyi.jpg"; 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.
好了,小伙伴们是否有了新的认识了呢,希望大家能够喜欢。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 梁汉文2008-EDMONDHITS48[香港]3CD[WAV+CUE]
- 国风大师纯音系列《童丽-[渭城曲]》1CD[WAV分轨][593.5MB]
- 国风大师纯音系列《许菱子《烧筝2》古筝曲集》1CD[WAV分轨][1.3GB]
- 王子异《1996 Part.2》[320K/MP3][18.29MB]
- 群星.1994-宝丽金最倾情3CD【宝丽金】【WAV+CUE】
- 乐俊亨.2024-同泪【CharioticMusic】【FLAC分轨】
- 何耀珊.2006-收获【华纳】【WAV+CUE】
- 梁汉文1994-壹精选[华星][WAV+CUE]
- 洪荣宏1981-歹路不可行·相思雨(飞跃复刻版)[光美][WAV+CUE]
- 旅行团2015-10Day’s[来福胶泥][WAV+CUE]
- 龙千玉.2011-卡将哟【豪记】【WAV+CUE】
- 蔣志光.1993-多情多寂寞(国专)【BMG】【WAV+CUE】
- 陈慧娴.1996-雪映美白96演唱会2CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 王子异《1996 Part.2》[FLAC/分轨][50.66MB]
- 贵族音乐《古典名曲与轻音乐钢琴 打开宝宝睡眠开关》[320K/MP3][155.91MB]