// // GET: /User/Create public ActionResult Create() { if (!PathModel.path.Equals(PathModel.root)) { //判断当前路径 该用户是否有Create权限 int User_Id = _entities.Users.FirstOrDefault(x => x.Name == System.Web.HttpContext.Current.User.Identity.Name).Id; int Path_Id = _entities.Paths.FirstOrDefault(x => x.Name == PathModel.path).Id; var right = _entities.Rights.FirstOrDefault(x => x.User_Id == User_Id && x.Path_Id == Path_Id); if (right != null && right.Create_right) { return View(); } else { ViewBag.ErrorMessage = "You have no create right on this folder!"; PathManager filesTree = new PathManager(PathModel.path); return View("Index", filesTree); } } else { ViewBag.ErrorMessage = "!! You can not create under root"; PathManager filesTree = new PathManager(PathModel.path); return View("Index", filesTree); } }
public PathManager(string path) { //this.virtual_Path = path.Substring(path.IndexOf("root")); //获取文件夹名称和物理路径 this.Name = path.Substring(path.LastIndexOf('\\') + 1); this.Path = path; //获取文件夹下全部文件路径 string[] filePaths = System.IO.Directory.GetFiles(path); if (filePaths != null) { foreach (string filepath in filePaths) { FileInfo file = new FileInfo(filepath); //获取单个文件 this.files.Add(file); FileModel fileModel = new FileModel(); fileModel.Name = filepath.Substring(filepath.LastIndexOf('\\') + 1); fileModel.Path = filepath; fileModel.Size = file.Length.ToString(); fileModel.Type = "file"; fileModel.Date = file.CreationTime.ToString(); filelist.Add(fileModel); } } this.Files = files; this.FileList = filelist; //获取文件夹下全部子文件夹路径 string[] directories = System.IO.Directory.GetDirectories(path); if (directories != null) { foreach (string directory in directories) { PathManager folder = new PathManager(directory); this.folders.Add(folder); DirectoryInfo dir = new DirectoryInfo(directory); FolderModel folderModel = new FolderModel(); folderModel.Name = directory.Substring(directory.LastIndexOf('\\') + 1); folderModel.Path = directory; folderModel.Size = ""; folderModel.Type = "folder"; folderModel.Date = dir.CreationTime.ToString(); folderlist.Add(folderModel); } } else { this.hasSubFolder = false; } this.Folders = folders; this.FolderList = folderlist; }
public ActionResult ConfirmationOnDelete(string path) { if (!path.Equals(PathModel.root)) { ViewBag.PathToDelete = path; return View(); } else { ViewBag.ErrorMessage = "!!You can not delete root"; PathManager filesTree = new PathManager(path); return View("Index", filesTree); } }
public ActionResult Create(PathModel model) { if (!ModelState.IsValid) return View(); string name = model.Name; string new_path = PathModel.path + '\\' + name; if (_entities.Paths.FirstOrDefault(m => m.Name == new_path) != null) { PathManager filesTree = new PathManager(PathModel.path); return View("Index", filesTree); } try { System.IO.Directory.CreateDirectory(new_path); // TODO: Add insert logic here Paths p = new Paths(); p.Name = new_path; string n = System.Web.HttpContext.Current.User.Identity.Name; p.Creator_Id = _entities.Users.FirstOrDefault(m => m.Name == n).Id; p.Create_Date = DateTime.Now; _entities.AddToPaths(p); _entities.SaveChanges(); //log _logRespository = new AddFolderOrFileLog(); _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name, new_path, 0); PathManager filesTree = new PathManager(PathModel.path); return View("Index", filesTree); } catch { PathManager filesTree = new PathManager(PathModel.path); return View("Index", filesTree); } }
// // GET: /Path/ public ActionResult Index() { //if (IsActive()) //{ PathModel.root = _xmlHelper.GetPhysicalPath();//System.Web.HttpContext.Current.Server.MapPath("/root"); PathManager filesTree = new PathManager(PathModel.root); PathModel.path = PathModel.root; return View(filesTree); //} //else // return RedirectToAction("Index", "Welcome"); }
public ActionResult GetFolder(string path) { PathManager filesTree = new PathManager(path); PathModel.path = path; return View("Index", filesTree); }
public ActionResult GetBack(string path) { //if ((path.IndexOf("root") + 4) != path.Length) if (!path.Equals(PathModel.root)) { int length = path.LastIndexOf('\\'); string parent = path.Substring(0, length); PathManager filesTree = new PathManager(parent); PathModel.path = parent; return View("Index", filesTree); } else { PathManager filesTree = new PathManager(path); return View("Index", filesTree); } }
public ActionResult EnterFolder(string path) { if ((path.LastIndexOf("\\") + 1) == path.Length) { path = path.Substring(0, path.Length - 1); } if (path.Contains(PathModel.root)) { try { PathManager filesTree = new PathManager(path); PathModel.path = path; return View("Index", filesTree); } catch { ViewBag.ErrorMessage = "!!InValid path"; PathModel.path = PathModel.root; PathManager filesTree = new PathManager(PathModel.root); return View("Index", filesTree); } } else { ViewBag.ErrorMessage = "!!InValid path"; PathModel.path = PathModel.root; PathManager filesTree = new PathManager(PathModel.root); return View("Index", filesTree); } }
public ActionResult Create(PathModel model) { if (!ModelState.IsValid) return View(); string name = model.Name; string new_path = PathModel.path + '\\' + name; if (_entities.Paths.FirstOrDefault(m => m.Name == new_path) != null) { PathManager filesTree = new PathManager(PathModel.path); return View("Index", filesTree); } try { System.IO.Directory.CreateDirectory(new_path); // Add insert logic Paths p = new Paths(); p.Name = new_path; string n = System.Web.HttpContext.Current.User.Identity.Name; int User_Id = _entities.Users.FirstOrDefault(m => m.Name == n).Id; p.Creator_Id = User_Id; p.Create_Date = DateTime.Now; _entities.AddToPaths(p); _entities.SaveChanges(); //add log _logRespository = new AddFolderOrFileLog(); _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name, new_path, 0); //auto inheritant rights RightType rt = 0; int Parent_Path_Id = _entities.Paths.FirstOrDefault(m => m.Name == PathModel.path).Id; int Path_Id = _entities.Paths.FirstOrDefault(m => m.Name == new_path).Id; Rights parent = _entities.Rights.FirstOrDefault(r => r.User_Id == User_Id && r.Path_Id == Parent_Path_Id); if(parent.Create_right) rt |= RightType.Create; if (parent.Upload_right) rt |= RightType.Upload; if (parent.Download_right) rt |= RightType.Download; if (parent.Delete_right) rt |= RightType.Delete; if (parent.Read_right) rt |= RightType.Read; Rights right = new Rights(); right.User_Id = User_Id; right.Path_Id = Path_Id; right.Create_right = parent.Create_right; right.Upload_right = parent.Upload_right; right.Download_right = parent.Download_right; right.Delete_right = parent.Delete_right; right.Read_right = parent.Read_right; _entities.AddToRights(right); _entities.SaveChanges(); //log _logRespository = new GrantRightLog(); _logRespository.AddLog( _entities.Users.FirstOrDefault(x => x.Id == User_Id).Name, _entities.Paths.FirstOrDefault(x => x.Id == Path_Id).Name, (int)rt); PathManager filesTree = new PathManager(PathModel.path); return View("Index", filesTree); } catch { PathManager filesTree = new PathManager(PathModel.path); return View("Index", filesTree); } }
public ActionResult Delete(string path) { PathManager filesTree; if (!path.Equals(PathModel.root)) { //判断该用户对该路径是否用delete权限 int User_Id = _entities.Users.FirstOrDefault(x => x.Name == System.Web.HttpContext.Current.User.Identity.Name).Id; int Path_Id = _entities.Paths.FirstOrDefault(x => x.Name == path).Id; var right = _entities.Rights.FirstOrDefault(x => x.User_Id == User_Id && x.Path_Id == Path_Id); if (right != null && right.Delete_right) { Paths p = _entities.Paths.FirstOrDefault(x => x.Name == path); if (p != null) { var sub_paths = from c in _entities.Paths where c.Name.Contains(path+ "\\") select c; List<Paths> sub_path_list = sub_paths.ToList(); // int sub_Path_Id; foreach (var item in sub_path_list) { sub_Path_Id = _entities.Paths.FirstOrDefault(x => x.Name == item.Name).Id; var sub_Path_right=_entities.Rights.FirstOrDefault(r=>r.User_Id==User_Id&&r.Path_Id==sub_Path_Id); if (sub_Path_right == null || !sub_Path_right.Delete_right) { ViewBag.ErrorMessage = "Make sure you have delete right on all sub folders!"; filesTree = new PathManager(path); return View("Index", filesTree); } } //log _logRespository = new DeleteFolderOrFileLog(); _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name, path, 0); string[] filePaths = System.IO.Directory.GetFiles(path); if (filePaths != null) { foreach (string filepath in filePaths) { _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name, filepath, 0); } } foreach (var item in sub_path_list) { _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name, item.Name, 0); string[] filePaths2 = System.IO.Directory.GetFiles(item.Name); if (filePaths != null) { foreach (string filepath in filePaths2) { _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name, filepath, 0); } } } System.IO.Directory.Delete(path, true); _entities.ExecuteStoreCommand("delete from Paths where Name = '" + path + "'");//.DeleteObject(p); _entities.ExecuteStoreCommand("delete from Paths where Name like '" + path + "\\" + "%'"); _entities.SaveChanges(); } int length = path.LastIndexOf('\\'); string parent = path.Substring(0, length); filesTree = new PathManager(parent); PathModel.path = parent; return View("Index", filesTree); } else { ViewBag.ErrorMessage = "Make sure you have delete right on this folder"; filesTree = new PathManager(path); return View("Index", filesTree); } } else { ViewBag.ErrorMessage = "You can not delete root!"; filesTree = new PathManager(path); return View("Index", filesTree); } }
// // GET: /UserAction/ // // GET: /Path/ public ActionResult Index() { PathModel.root = _xmlHelper.GetPhysicalPath(); PathManager filesTree = new PathManager(PathModel.root); PathModel.path = PathModel.root; return View(filesTree); }
public ActionResult GetFolder(string path) { //判断该用户对该路径是否用read权限 int User_Id = _entities.Users.FirstOrDefault(x => x.Name == System.Web.HttpContext.Current.User.Identity.Name).Id; int Path_Id = _entities.Paths.FirstOrDefault(x => x.Name == path).Id; var right = _entities.Rights.FirstOrDefault(x => x.User_Id == User_Id && x.Path_Id == Path_Id); if (right != null && right.Read_right) { PathManager filesTree = new PathManager(path); PathModel.path = path; return View("Index", filesTree); } else { ViewBag.ErrorMessage = "Make sure you have read right on this folder"; PathManager filesTree = new PathManager(PathModel.path); //PathModel.path = path; return View("Index", filesTree); } }
public ActionResult EnterFolder(string path) { if ((path.LastIndexOf("\\") + 1) == path.Length) { path = path.Substring(0, path.Length - 1); } if (!path.Equals(PathModel.root) && path.Contains(PathModel.root)) { try { //判断该用户对该路径是否用read权限 int User_Id = _entities.Users.FirstOrDefault(x => x.Name == System.Web.HttpContext.Current.User.Identity.Name).Id; int Path_Id = _entities.Paths.FirstOrDefault(x => x.Name == path).Id; var right = _entities.Rights.FirstOrDefault(x => x.User_Id == User_Id && x.Path_Id == Path_Id); if (right != null && right.Read_right) { PathManager filesTree = new PathManager(path); PathModel.path = path; return View("Index", filesTree); } else { PathManager filesTree = new PathManager(PathModel.path); //PathModel.path = path; return View("Index", filesTree); } } catch { ViewBag.ErrorMessage = "!!InValid path"; PathModel.path = PathModel.root; PathManager filesTree = new PathManager(PathModel.root); return View("Index", filesTree); } } else { PathModel.path = PathModel.root; PathManager filesTree = new PathManager(PathModel.root); return View("Index", filesTree); } }
public ActionResult Download(string path) { //判断当前路径 该用户是否有Download权限 int User_Id = _entities.Users.FirstOrDefault(x => x.Name == System.Web.HttpContext.Current.User.Identity.Name).Id; int Path_Id = _entities.Paths.FirstOrDefault(x => x.Name == PathModel.path).Id; var right = _entities.Rights.FirstOrDefault(x => x.User_Id == User_Id && x.Path_Id == Path_Id); if (right != null && right.Download_right) { string url = path;//AppDomain.CurrentDomain.BaseDirectory + "/"+path; return File(url, "text/plain", Path.GetFileName(url)); } else { ViewBag.ErrorMessage = "!!You have no download right on this folder"; PathManager filesTree = new PathManager(PathModel.path); return View("Index", filesTree); } }
public ActionResult DeleteFile(string path) { string dir = path.Substring(0, path.LastIndexOf("\\")); if (!dir.Equals(PathModel.root)) { //判断该用户对该路径是否用delete权限 int User_Id = _entities.Users.FirstOrDefault(x => x.Name == System.Web.HttpContext.Current.User.Identity.Name).Id; int Path_Id = _entities.Paths.FirstOrDefault(x => x.Name == dir).Id; var right = _entities.Rights.FirstOrDefault(x => x.User_Id == User_Id && x.Path_Id == Path_Id); if (right != null && right.Delete_right) { Paths p = _entities.Paths.FirstOrDefault(x => x.Name == dir); if (p != null) { if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); //log _logRespository = new DeleteFolderOrFileLog(); _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name, path, 0); } } } else { ViewBag.ErrorMessage = "Make sure you have delete right on this folder"; } } PathManager filesTree = new PathManager(dir); return View("Index", filesTree); }
public ActionResult Delete(string path) { //if ((path.IndexOf("root") + 4) != path.Length) if (!path.Equals(PathModel.root)) { Paths p = _entities.Paths.FirstOrDefault(x => x.Name == path); if (p != null) { var sub_paths = from c in _entities.Paths where c.Name.Contains(path + "\\") select c; List<Paths> sub_path_list = sub_paths.ToList(); //log _logRespository = new DeleteFolderOrFileLog(); _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name, path, 0); string[] filePaths = System.IO.Directory.GetFiles(path); if (filePaths != null) { foreach (string filepath in filePaths) { _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name, filepath, 0); } } foreach (var item in sub_path_list) { _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name, item.Name, 0); string[] filePaths2 = System.IO.Directory.GetFiles(item.Name); if (filePaths != null) { foreach (string filepath in filePaths2) { _logRespository.AddLog(System.Web.HttpContext.Current.User.Identity.Name, filepath, 0); } } } System.IO.Directory.Delete(path, true); _entities.ExecuteStoreCommand("delete from Paths where Name = '" + path + "'");//.DeleteObject(p); _entities.ExecuteStoreCommand("delete from Paths where Name like '" + path + "\\" + "%'"); _entities.SaveChanges(); } int length = path.LastIndexOf('\\'); string parent = path.Substring(0, length); PathManager filesTree = new PathManager(parent); PathModel.path = parent; return View("Index", filesTree); } else { PathManager filesTree = new PathManager(path); return View("Index", filesTree); } }
public ActionResult UpLoad(HttpPostedFileBase file) { if (!PathModel.path.Equals(PathModel.root)) { //判断当前路径 该用户是否有Upload权限 int User_Id = _entities.Users.FirstOrDefault(x => x.Name == System.Web.HttpContext.Current.User.Identity.Name).Id; int Path_Id = _entities.Paths.FirstOrDefault(x => x.Name == PathModel.path).Id; var right = _entities.Rights.FirstOrDefault(x => x.User_Id == User_Id && x.Path_Id == Path_Id); if (right != null && right.Upload_right) { // Verify that the user selected a file if (file != null && file.ContentLength > 0) { // extract only the fielname var fileName = Path.GetFileName(file.FileName); // store the file inside ~/App_Data/uploads folder var path = Path.Combine(PathModel.path, fileName); file.SaveAs(path); } } else { ViewBag.ErrorMessage = "!!You have no upload right on this folder"; } } else { ViewBag.ErrorMessage = "!!You can not upload under root"; } PathManager filesTree = new PathManager(PathModel.path); return View("Index", filesTree); }