利用C#怎么將圖片下載到服務器?相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。

C#實現(xiàn)把圖片下載到服務器代碼
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("/tupian/20230522/404.html
DownloadFile方法里的address就是你要拼成的遠程服務器上的URL.看完上述內容,你們掌握利用C#怎么將圖片下載到服務器的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
分享文章:利用C#怎么將圖片下載到服務器-創(chuàng)新互聯(lián)
瀏覽路徑:http://chinadenli.net/article30/ccjipo.html
成都網站建設公司_創(chuàng)新互聯(lián),為您提供外貿網站建設、網站改版、動態(tài)網站、ChatGPT、App開發(fā)、云服務器
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內容