• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    C#实现把图片下载到服务器代码

    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.

    好了,小伙伴们是否有了新的认识了呢,希望大家能够喜欢。

    您可能感兴趣的文章:
    • Asp.net(C#)读取数据库并生成JS文件制作首页图片切换效果(附demo源码下载)
    • C#实现上传下载图片
    • C#.NET中如何批量插入大量数据到数据库中
    • c#批量上传图片到服务器示例分享
    • C#实现SQL批量插入数据到表的方法
    • C#/.Net 中快速批量给SQLite数据库插入测试数据
    • C#实现的文件批量重命名功能示例
    • C#实现批量下载图片到本地示例代码
    上一篇:asp.net微信开发(开发者接入)
    下一篇:ASP.NET图片上传实例(附源码)
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    C#实现把图片下载到服务器代码 实现,把,图片下载,到,服务器,