Ejemplo n.º 1
0
 public List<DataGroupModel> GetFolder(string path)
 {
     var pathtemp = Server.MapPath("~\\Upload\\" + path);
     DirectoryInfo curFolder = new DirectoryInfo(pathtemp);
     var childFolder = curFolder.GetDirectories();
     if (childFolder.Length > 0)
     {
         var result = new List<DataGroupModel>();
         foreach (var fol in childFolder)
         {
             var f = new DataGroupModel()
             {
                 text = fol.Name,
                 href = path + "\\" + fol.Name
             };
             f.nodes = GetFolder(f.href);
             result.Add(f);
         }
         return result;
     }
     return null;
 }
Ejemplo n.º 2
0
        public ActionResult GetFile(string path, string type)
        {
            var pathtemp = Server.MapPath("~\\Upload\\" + path);

            var picture = new List<string>()
            {
                ".JPEG",".TIFF",".PNG",".GIF",".JPG"
            };

            var video = new List<string>()
            {
                ".MP4",".WEBM",".OGG"
            };

            var data = new List<DataGroupModel>();
            List<string> typeList = null;
            if (Directory.Exists(pathtemp))
            {
                switch (type)
                {
                    case "picture":
                        typeList = picture;
                        break;
                    case "video":
                        typeList = video;
                        break;
                }
                DirectoryInfo curFolder = new DirectoryInfo(pathtemp);
                foreach (FileInfo file in curFolder.GetFiles())
                {

                    var typeFile = file.Extension.ToUpper();
                    var da = new DataGroupModel()
                    {
                        text = file.Name,
                        href = "\\Upload\\" + path + "\\" + file.Name
                    };

                    if (typeList == null )
                    {
                        data.Add(da);
                    }else if (typeList.Contains(typeFile))
                    {
                        data.Add(da);
                    }

                }
            }

            return Json(JsonConvert.SerializeObject(data,
                Formatting.Indented,
                new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore }));
        }