zoukankan      html  css  js  c++  java
  • 下载

    一丶下载服务器图片

     1 static void Main(string[] args)
     2 {
     3         try
     4          {
     5              qds107762222_dbEntities db = new qds107762222_dbEntities();
     6              var zucai_Team = db.Set<zucai_team>().ToList();
     7              foreach (var item in zucai_Team)
     8              {
     9                  if (!String.IsNullOrEmpty(item.ImgPath))
    10                  {
    11                      string[] str = item.ImgPath.Split(new char[] { '/' });
    12                      var imgName = str[str.Length - 1];
    13                      Console.WriteLine(item.ImgPath);
    14 
    15                      string path = "G:\img1\" + imgName;
    16                      WebClient web = new WebClient();
    17                      if (!File.Exists(path))
    18                      {
    19                          web.DownloadFile(item.ImgPath, path);
    20                      }
    21                  }
    22                    
    23              }
    24 
    25          }
    26          catch (Exception ex)
    27          {
    28 
    29              throw ex;
    30          }
    31          Console.WriteLine("ok");
    32          Console.ReadKey();
    33 }
    下载

     二丶下载文件

     1         public ActionResult DownloadFile(string fileRelativePath)
     2         {
     3             //1.根据文件相对路径获取文件绝对路径
     4             string fileAbsolutelyPath = Server.MapPath("~" + fileRelativePath);
     5             //2.获取文件信息
     6             FileInfo file = new FileInfo(fileAbsolutelyPath );
     7 
     8             if (file.Exists)
     9             {
    10                 //3.获取指定文件名的 MIME 映射
    11                 string contentType = MimeMapping.GetMimeMapping(fileAbsolutelyPath );
    12                 //4.下载文件
    13                 return File(objFileBasePath, contentType, file.Name);
    14             }
    15             else
    16             {
    17                 return Content("文件不存在");
    18             }
    19 
    20         }
    View Code
    作者:chenze
    出处:https://www.cnblogs.com/chenze-Index/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    如果文中有什么错误,欢迎指出。以免更多的人被误导。
  • 相关阅读:
    JavaScript DOM 选择器 querySelector
    JavaScript call()函数的应用
    flex布局中 align-items 和 align-content的区别
    移动端WEB
    触发器与存储过程
    游标
    触发器---存储过程---存储函数
    mysql中check无效
    mysql唯一性约束和索引
    分页查询
  • 原文地址:https://www.cnblogs.com/chenze-Index/p/9517064.html
Copyright © 2011-2022 走看看