zoukankan      html  css  js  c++  java
  • 使用C#读取网站相对路径文件夹下所有图片

         public JsonResult GetCourseInitCover()
            {
                //设置相对路径
                string imgurl = Server.MapPath("~/Content/images");
    
                //根据相对路径,读取所有文件,并且不查找子文件夹。之后筛选格式是图片的文件
                var strs = System.IO.Directory.GetFiles(imgurl, "*.*", System.IO.SearchOption.TopDirectoryOnly).Where(s => s.EndsWith(".jpg") || s.EndsWith(".gif") || s.EndsWith(".bmp") || s.EndsWith(".png"));
    
                List<KeyName> filelist = new List<KeyName>();
                foreach (string file in strs)
                {
                    KeyName item = new KeyName();
                    //读取文件信息
                    System.IO.FileInfo fi = new System.IO.FileInfo(file);
                    if (fi.Extension == ".jpg" || fi.Extension == ".gif" || fi.Extension == ".bmp" || fi.Extension == ".png")
                    {
                        item.Name = fi.Name;
                        filelist.Add(item);
                    }
                }
    
                //拼装返回参数
                var result = from dir in filelist
                             select new
                             {
                                 key = "/Content/images/" + dir.Name,
                                 value = dir.Name.Split('.')[0]
                             };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
  • 相关阅读:
    js练习题2
    js样式
    js小练习
    css动画样式
    css盒子、布局样式
    css一般样式
    css样式、选择器
    html表格、表单
    html 标签
    mysql连接查询,子查询,联合查询
  • 原文地址:https://www.cnblogs.com/sanqianjin/p/5141605.html
Copyright © 2011-2022 走看看