internal static ActionResult GetSourceFolders() { ActionResult actionResult = new ActionResult(); string path = Path.Combine(Globals.ApplicationMapPath, "DesktopModules"); List <string> controlfolders = ( from subdirectory in Directory.GetDirectories(path, "*", SearchOption.AllDirectories) select subdirectory).ToList(); List <TempExt> response = new List <TempExt>(); int appPathLen = Globals.ApplicationMapPath.Length + 1; foreach (string folder in controlfolders) { int moduleControls = Directory.EnumerateFiles(folder, "*.*", SearchOption.TopDirectoryOnly) .Count(s => s.EndsWith(".ascx") || s.EndsWith(".cshtml") || s.EndsWith(".vbhtml") || s.EndsWith(".html") || s.EndsWith(".htm")); if (moduleControls > 0) { string shortFolder = folder.Substring(appPathLen).Replace('\\', '/'); TempExt item = new TempExt { Key = shortFolder.ToLower(), Value = shortFolder }; response.Add(item); } } actionResult.Data = response; actionResult.IsSuccess = true; return(actionResult); }
private static void AddFiles(ICollection <TempExt> collection, string path, string root, string filter) { string[] files = Directory.GetFiles(path, filter); foreach (string strFile in files) { string file = root.Replace('\\', '/') + "/" + Path.GetFileName(strFile); TempExt item = new TempExt { Key = file.ToLower(), Value = file }; collection.Add(item); } }
internal static ActionResult GetIcons(string controlPath) { ActionResult actionResult = new ActionResult(); List <TempExt> response = new List <TempExt> { new TempExt { Key = "", Value = "Please Select" } }; if (!string.IsNullOrEmpty(controlPath)) { int idx = controlPath.LastIndexOf("/", StringComparison.Ordinal); string root = controlPath.Substring(0, Math.Max(0, idx)); string path = Path.Combine(Globals.ApplicationMapPath, root.Replace('/', '\\')); if (Directory.Exists(path)) { string[] files = Directory.GetFiles(path); if (files.Length > 0) { string[] extensions = Globals.glbImageFileTypes.ToLowerInvariant().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string file in files) { string ext = Path.GetExtension(file) ?? ""; string extension = ext.Length <= 1 ? "" : ext.Substring(1).ToLowerInvariant(); if (extensions.Contains(extension)) { path = Path.GetFileName(file); if (path != null) { TempExt item = new TempExt { Key = path.ToLower(), Value = Path.GetFileName(file) }; response.Add(item); } } } } } } actionResult.Data = response; actionResult.IsSuccess = true; return(actionResult); }