C#實(shí)現(xiàn)把圖片下載到服務(wù)器代碼
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)文章
asp.net動(dòng)態(tài)加載自定義控件的方法
這篇文章主要介紹了asp.net動(dòng)態(tài)加載自定義控件的方法,涉及asp.net動(dòng)態(tài)加載控件的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-04-04
asp.net后臺(tái)cs中的JSON格式變量在前臺(tái)Js中調(diào)用方法(前后臺(tái)示例代碼)
本文主要介紹下asp.net后臺(tái)cs中的JSON格式變量在前臺(tái)Js中調(diào)用方法,下面是前后臺(tái)的實(shí)現(xiàn)代碼,感興趣的朋友可以參考下哈,下對(duì)大家有所幫助2013-06-06
Ext.net中的MessageBox的簡單應(yīng)用實(shí)現(xiàn)代碼
今天在項(xiàng)目中要用到簡單的MessageBox的使用。在Ext.net中沒有Winform那么簡單,直接寫MessageBox.show()的方法。于是就去examples.ext.net的例子網(wǎng)站找,想找到個(gè)實(shí)際能用的2012-03-03
asp.net 使用js分頁實(shí)現(xiàn)異步加載數(shù)據(jù)
這篇文章主要介紹了asp.net使用js分頁實(shí)現(xiàn)異步加載數(shù)據(jù),需要的朋友可以參考下2014-04-04
如何在ASP.NET Core中使用ViewComponent
這篇文章主要介紹了如何在ASP.NET Core中使用ViewComponent,幫助大家更好的理解和學(xué)習(xí)使用.net技術(shù),感興趣的朋友可以了解下2021-04-04
ASP.net(c#)用類的思想實(shí)現(xiàn)插入數(shù)據(jù)到ACCESS例子
ASP.net(c#)用類的思想實(shí)現(xiàn)插入數(shù)據(jù)到ACCESS例子...2007-07-07

