最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#實(shí)現(xiàn)把圖片下載到服務(wù)器代碼

 更新時(shí)間:2015年11月16日 08:58:55   投稿:hebedich  
本文給大家分享的是實(shí)現(xiàn)這樣一個(gè)功能,想將遠(yuǎn)程服務(wù)器的圖片下載到本地主機(jī),圖片的名稱就是數(shù)據(jù)庫的一個(gè)字段,圖片不是以二進(jìn)制的形式存儲(chǔ)在數(shù)據(jù)庫的,數(shù)據(jù)庫存儲(chǔ)的只是圖片的名詞。

C#實(shí)現(xiàn)把圖片下載到服務(wù)器代碼

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>根據(jù)網(wǎng)址把圖片下載到服務(wù)器</title>
</head>
<body>
 <form id="form1" runat="server">
 <div>
 圖片網(wǎng)址:<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");

    //根據(jù)網(wǎng)址下載文件
    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就是你要拼成的遠(yuǎn)程服務(wù)器上的URL.

好了,小伙伴們是否有了新的認(rèn)識(shí)了呢,希望大家能夠喜歡。

相關(guān)文章

最新評論

华亭县| 博爱县| 曲松县| 汾西县| 芜湖县| 千阳县| 土默特右旗| 虞城县| 运城市| 沾化县| 高邑县| 安仁县| 泸水县| 枣庄市| 尼玛县| 威宁| 咸阳市| 德惠市| 雷波县| 河西区| 贺州市| 鄂伦春自治旗| 霍州市| 姜堰市| 蒙山县| 华池县| 康平县| 武安市| 瑞昌市| 洛川县| 大厂| 宝山区| 江西省| 衡东县| 岳池县| 玉门市| 遵义市| 新密市| 湖北省| 镇平县| 津市市|