public ActionResult FileZone(FileZone s) { var location = s.CurrentDirectory; bool isSavedSuccessfully = true; string fName = ""; try { foreach (string fileName in Request.Files) { HttpPostedFileBase file = Request.Files[fileName]; //Save file content goes here fName = file.FileName; if (file != null && file.ContentLength > 0) { string pathString; if (location != null) { pathString = new DirectoryInfo(location).ToString(); } else { pathString = new DirectoryInfo(Server.MapPath(@"\") + "FileZone").ToString(); } var fileName1 = Path.GetFileName(file.FileName); bool isExists = System.IO.Directory.Exists(pathString); if (!isExists) System.IO.Directory.CreateDirectory(pathString); var path = string.Format("{0}\\{1}", pathString, file.FileName); file.SaveAs(path); } } } catch (Exception ex) { isSavedSuccessfully = false; } if (isSavedSuccessfully) { return View("FileZone", s); } else { return Json(new { Message = "Error in saving file" }); } }
public ActionResult partialFileZone(string folder) { DirectoryInfo di; List<Item> files = new List<Item>(); if (folder == "" || folder == null) { di = new DirectoryInfo(Server.MapPath(@"\") + "FileZone"); folder = Server.MapPath(@"\") + "FileZone"; } else { di = new DirectoryInfo(folder); } foreach (var fi in di.GetFiles()) { Item item = new Item(); var name = fi.Name.ToString(); item.Title = name; item.Size = fi.Length; item.Format = fi.Extension; files.Add(item); } List<System.IO.DirectoryInfo> dirs = new List<System.IO.DirectoryInfo>(); foreach (System.IO.DirectoryInfo dir in di.GetDirectories()) { dirs.Add(dir); } FileZone fileClass = new FileZone(); fileClass.Files = files; fileClass.CurrentDirectory = folder; fileClass.Folders = dirs; return PartialView(fileClass); }
public ActionResult FileZone() { if (User.Identity.IsAuthenticated) { FileZone s = new FileZone(); s.CurrentDirectory = Server.MapPath(@"\") + "FileZone"; return View(s); } return RedirectToAction("Login", "Account"); }