Net Core 下載圖片


直接上代碼

string url = https://www.cnblogs.com/images/logo_small.gif;
//獲取網站當前根目錄
string sWebRootFolder = hostingEnv.WebRootPath;
//保存圖片路徑
var savePath = string.Format("\\Uploads\\{0}\\{1}\\{2}\\", DateTime.Now.Year, DateTime.Now.Month.ToString("D2"), DateTime.Now.Day.ToString("D2"));
//文件名
string filename = System.IO.Path.GetFileName(url);
//擴展名
string extension = System.IO.Path.GetExtension(url);
savePath = sWebRootFolder + savePath;
//無夾創建
if (!Directory.Exists(savePath))
{
  Directory.CreateDirectory(savePath);
}
WebClient mywebclient = new WebClient();
//下載文件
mywebclient.DownloadFile(url, savePath + filename);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM