欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#抓取網(wǎng)絡(luò)圖片保存到本地的實(shí)現(xiàn)方法

 更新時(shí)間:2018年01月05日 09:52:43   作者:葉長種  
下面小編就為大家分享一篇C#抓取網(wǎng)絡(luò)圖片保存到本地的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

實(shí)例如下所示:

System.Net.WebClient myWebClient = new System.Net.WebClient();
  //將頭像保存到服務(wù)器
     string virPath = "/Uploads/AppImage/" + user.Id + "/";
     CreateDir(virPath);
     string fileName = Guid.NewGuid().ToString() + ".png";
     myWebClient.DownloadFile(headimgurl, System.Web.HttpContext.Current.Request.PhysicalApplicationPath + virPath + fileName);
     user.Portrait = virPath + fileName;
#region 創(chuàng)建目錄
  /// <summary>
  /// 創(chuàng)建目錄
  /// </summary>
  /// <param name="dir">要?jiǎng)?chuàng)建的目錄路徑包括目錄名</param>
  public static void CreateDir(string dir)
  {
   if (dir.Length == 0) return;
   if (!Directory.Exists(System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "\\" + dir))
    Directory.CreateDirectory(System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "\\" + dir)
     ;
  }
  #endregion

以上這篇C#抓取網(wǎng)絡(luò)圖片保存到本地的實(shí)現(xiàn)方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論