东营信息港首页,尚国胜,泰山天气预报一周
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.
好了,小伙伴们是否有了新的认识了呢,希望大家能够喜欢。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Net Core Web Api项目与在NginX下发布的方法
asp.net core3.1 引用的元包dll版本兼容性问题解决方案
IdentityServer4实现.Net Core API接口权限认证(快速入门)
ASP.NET Core MVC通过IViewLocationExpander扩展视图搜索路径的实现
网友评论