private void setFiles(string path, JResult res, string directory) { if (!Directory.Exists(path)) { res.msg = directory + " not exist"; } else { res.data = GetFiles(path); res.isSuccess = true; } }
public JsonResult SaveFile(string key, string fileName, string content) { string path = Server.MapPath("~"); JResult res = new JResult(); try { switch (key) { case "Controllers": path += "Scripts\\Controllers\\" + fileName; System.IO.File.WriteAllText(path, content); break; case "Services": path += "Scripts\\Services\\" + fileName; System.IO.File.WriteAllText(path, content); break; case "Layouts": path += "Templates\\Layouts\\" + fileName; System.IO.File.WriteAllText(path, content); break; case "Components": path += "Templates\\Components\\" + fileName; System.IO.File.WriteAllText(path, content); break; case "Widgets": path += "Templates\\Widgets\\" + fileName; System.IO.File.WriteAllText(path, content); break; } res.isSuccess = true; res.msg = "Successfully saved."; } catch (Exception ex) { res.msg = ex.Message; } return(Json(res, JsonRequestBehavior.AllowGet)); }
public JsonResult GetFileList(string directory) { JResult res = new JResult(); try { string path = Server.MapPath("~"); switch (directory) { case "Controllers": case "Services": path += "Scripts\\" + directory; setFiles(path, res, directory); break; case "Layouts": path += "Templates\\Layouts"; setFiles(path, res, directory); break; case "Components": path += "Templates\\Components"; setFiles(path, res, directory); break; case "Widgets": path += "Templates\\Widgets"; setFiles(path, res, directory); break; } } catch (Exception ex) { res.msg = ex.Message; } return(Json(res, JsonRequestBehavior.AllowGet)); }