public ActionResult Share(String name) { var chemin = (string)MySession.GetChemin(); User myUser = (User)MySession.GetUser(); string cheminFolder = string.Empty; if (chemin != null) { cheminFolder += (string)MySession.GetChemin(); } cheminFolder += name; FileSystemItem fileSystemItem = FileSystemItem.GetElement(cheminFolder, myUser.Id); if (fileSystemItem != null) { if (fileSystemItem.Shared) { //fileSystemItem.Shared = false; fileSystemItem.SetShare(false); } else { //fileSystemItem.Shared = true; fileSystemItem.SetShare(true); string lien = "https://localhost:44326/Home/DisplayFile?chemin=%2F" + cheminFolder + "&userName="******"<p>" + lien + "</p><br><a href=\"/\">Retour</a>"; return(Content(content, "text/html")); } fileSystemItem.SetShare(fileSystemItem.Shared); } return(RedirectToAction("Index", "Home", new { Chemin = chemin })); }
//************************************create file********************************** public bool CreateFile(HttpPostedFileBase file) { User user = (User)MySession.GetUser(); if (user.ajouterStockage(file.ContentLength)) { FileSystemItem result = createElement(file.FileName, false, file.ContentLength); if (result != null) { String[] words = file.FileName.Split('.'); string fileName = result.Id + "." + words[words.Length - 1]; string path = ""; path = result.Drive + Database.StoragePath; path = System.IO.Path.Combine(path, UserId.ToString()); CreateDir(path); path = System.IO.Path.Combine(path, fileName); file.SaveAs(path); user.Save(); return(true); } } return(false); }
// GET: LandingPage public ActionResult Index() { User user = (User)MySession.GetUser(); ViewBag.User = user; return(View()); }
public ActionResult Share(String name) { var chemin = (string)MySession.GetChemin(); User myUser = (User)MySession.GetUser(); string cheminFolder = string.Empty; if (chemin != null) { cheminFolder += (string)MySession.GetChemin(); } cheminFolder += name; FileSystemItem fileSystemItem = FileSystemItem.GetElement(cheminFolder, myUser.Id); if (fileSystemItem != null) { if (fileSystemItem.Shared) { fileSystemItem.Shared = false; } else { fileSystemItem.Shared = true; } fileSystemItem.SetShare(fileSystemItem.Shared); } return(RedirectToAction("Index", "Home", new { Chemin = chemin })); }
public ActionResult Delete(String name) { var chemin = (string)MySession.GetChemin(); string newPath = (string)MySession.GetChemin() + "/" + name; FileSystemItem fileSystemItem = FileSystemItem.GetElement(newPath, MySession.GetUser().Id); bool result = fileSystemItem.Delete(); return(RedirectToAction("Index", "Home", new { Chemin = chemin })); }
/*public ActionResult DisplayFile(String chemin) * { * //string chemin = MySession.GetChemin() as string; * FileSystemItem fsi = FileSystemItem.GetElement(chemin, MySession.GetUser().Id); * ViewBag.Chemin = fsi.Filename; * return View();*/ public ActionResult DisplayFile() { string chemin = Request.QueryString["chemin"]; int userId; if (Request.QueryString["userName"] == null) { userId = MySession.GetUser().Id; } else { userId = int.Parse(Request.QueryString["userName"]); } FileSystemItem fsi = FileSystemItem.GetElement(chemin, userId); bool logged = MySession.GetUser() != null; if (logged) { logged = MySession.GetUser().Id == fsi.UserId; } if (fsi != null && (fsi.Shared || logged)) { ViewBag.Chemin = fsi.Path; ViewBag.FileName = fsi.Name; ViewBag.UserId = fsi.UserId; switch (fsi.Extension.ToLower()) { case "png": case "jpeg": case "jpg": ViewBag.Type = "image"; break; case "mp4": ViewBag.Type = "video"; break; case "mp3": ViewBag.Type = "audio"; break; } if (ViewBag.Type == null) { return(RedirectToAction("Index", "LandingPage")); } return(View()); } return(RedirectToAction("Index", "LandingPage")); }
// GET: Folder public ActionResult AddFolder() { var name = Request.QueryString["foldername"]; User myUser = (User)MySession.GetUser(); FileSystemItem fileSystemItem = FileSystemItem.GetElement((string)MySession.GetChemin(), myUser.Id); bool result = fileSystemItem.createDirectory(name); String status = "nok"; if (result) { status = "ok"; } return(Content(status, "text/plain")); }
public ActionResult Rename() { var name = Request.QueryString["filename"]; string oldname = Request.QueryString["fileoldname"]; string status = "nok"; string newPath = (string)MySession.GetChemin() + "/" + oldname; FileSystemItem fileSystemItem = FileSystemItem.GetElement(newPath, MySession.GetUser().Id); bool result = fileSystemItem.Rename(name); if (result) { status = "ok"; } return(Content(status, "text/plain")); }
public ActionResult GetFile() { string chemin = Request.QueryString["chemin"]; // TODO fix int userId; if (Request.QueryString["userName"] == null) { userId = MySession.GetUser().Id; } else { userId = int.Parse(Request.QueryString["userName"]); } FileSystemItem fsi = FileSystemItem.GetElement(chemin, userId); if (fsi == null) { return(RedirectToAction("Index", "LandingPage")); } FileInfo file = new FileInfo(fsi.FilePath); if (file != null) { Response.Clear(); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + fsi.Name); FileStream myFS = new FileStream(fsi.FilePath, FileMode.Open); MemoryStream myMS = new MemoryStream(); myMS.SetLength(myFS.Length); myFS.Read(myMS.GetBuffer(), 0, (int)myFS.Length); myFS.Close(); myMS.Flush(); Response.BinaryWrite(myMS.ToArray()); Response.Flush(); myMS.Dispose(); myMS.Close(); Response.End(); } return(null); }
public ActionResult Download(String name) { var chemin = (string)MySession.GetChemin(); FileSystemItem item = FileSystemItem.GetElement(chemin + "/" + name, MySession.GetUser().Id); FileInfo file = new FileInfo(Path.Combine(Debug.LocalStorage(), name)); if (chemin != null) { file = new FileInfo(Path.Combine(Debug.LocalStorage(), chemin.ToString(), name)); } if (file != null) { string pathFile = file.FullName; string nameFile = file.Name; string nameNoExt = nameFile.Split('.')[0]; Response.Clear(); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + nameFile); FileStream myFS = new FileStream(item.FilePath, FileMode.Open); MemoryStream myMS = new MemoryStream(); myMS.SetLength(myFS.Length); myFS.Read(myMS.GetBuffer(), 0, (int)myFS.Length); myFS.Close(); myMS.Flush(); Response.BinaryWrite(myMS.ToArray()); Response.Flush(); myMS.Dispose(); myMS.Close(); Response.End(); } return(RedirectToAction("Index", "Home", new { Chemin = chemin })); }
public ActionResult Index(String name) { var chemin = (string)MySession.GetChemin(); FileInfo file = new FileInfo(Path.Combine(Debug.LocalStorage(), name)); FileSystemItem fsi = FileSystemItem.GetElement(chemin + "/" + name, MySession.GetUser().Id); DisplayContent displayContent = new DisplayContent(); displayContent.ProcessStart(fsi.FilePath); /*if (chemin != null) * { * string fileURL = Path.Combine(Debug.LocalStorage(), chemin.ToString(), name); * file = new FileInfo(fileURL); * * } * if (file.Exists) * { * if (ViewerModel.ExtensionImage.ToList().Contains(file.Extension.ToLower())) * { * DisplayContent displayContent = new DisplayContent(); * * displayContent.ProcessStart(file.ToString()); * * } * }*/ return(RedirectToAction("Index", "Home", new { Chemin = chemin })); }
public ActionResult Download(String name) { var chemin = (string)MySession.GetChemin(); User myUser = (User)MySession.GetUser(); FileSystemItem fileSystemItem = FileSystemItem.GetElement(name, myUser.Id); if (fileSystemItem != null) { string pathFolder = fileSystemItem.Path; string nameFolder = fileSystemItem.Name; string nameNoExt = nameFolder.Split('.')[0]; string startPath = @pathFolder + "\\" + nameNoExt + ".txt"; string zipPath = @pathFolder + "\\" + nameNoExt + ".zip"; if (!string.IsNullOrEmpty(zipPath)) { FileInfo zipFile = new FileInfo(Path.Combine(Debug.LocalStorage(), nameNoExt + ".zip")); if (chemin != null) { zipFile = new FileInfo(Path.Combine(Debug.LocalStorage(), chemin.ToString(), nameNoExt + ".zip")); } if (zipFile.Exists) { zipFile.Delete(); } ZipFile.CreateFromDirectory(startPath, zipPath, CompressionLevel.Fastest, true); Response.Clear(); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + nameFolder); FileStream myFS = new FileStream(zipPath, FileMode.Open); MemoryStream myMS = new MemoryStream(); myMS.SetLength(myFS.Length); myFS.Read(myMS.GetBuffer(), 0, (int)myFS.Length); myFS.Close(); myMS.Flush(); Response.BinaryWrite(myMS.ToArray()); Response.Flush(); myMS.Dispose(); myMS.Close(); Response.End(); FileInfo zipFile2 = new FileInfo(Path.Combine(Debug.LocalStorage(), nameNoExt + ".zip")); if (chemin != null) { zipFile2 = new FileInfo(Path.Combine(Debug.LocalStorage(), chemin.ToString(), nameNoExt + ".zip")); } if (zipFile2.Exists) { zipFile2.Delete(); } } } return(RedirectToAction("Index", "Home", new { Chemin = chemin })); }
public ActionResult Index(String c, String u) { string chemin = Request.QueryString["chemin"]; string userName = Request.QueryString["userName"]; if (chemin == "DisplayFile") { return(Redirect("DisplayFile")); } User user = MySession.GetUser(); if (user != null) { StorageManager sManager = StorageManager.Instance; var userStockageFree = user.StockageMax - user.Stockage; MySession.SetChemin(chemin); FileSystemItem fsi = FileSystemItem.GetElement(chemin, user.Id); if (!fsi.IsDir) { return(RedirectToAction("DisplayFile")); } FileSystemItem[] items = fsi.Getchilds().ToArray(); items = items.Where(i => i.UserId == user.Id).ToArray(); ViewBag.User = user; ViewBag.Items = items; ViewBag.Chemin = chemin; ViewBag.UserStockage = sManager.KilobyteToGygabyte(userStockageFree); return(View()); } else if (!string.IsNullOrEmpty(chemin) && !string.IsNullOrEmpty(userName)) { MySession.SetChemin(chemin); FileSystemItem fsi = FileSystemItem.GetElement(chemin, Int32.Parse(userName)); FileSystemItem[] items = fsi.Getchilds().Where(i => i.Shared).ToArray(); if (items != null && items.Count() > 0) { ViewBag.Items = items; ViewBag.Chemin = chemin; return(View()); } else if (fsi.IsDir) { ViewBag.Items = items; ViewBag.Chemin = chemin; return(View()); } else { return(RedirectToAction("Index", "LandingPage")); } } else { return(RedirectToAction("Index", "LandingPage")); } }
public ActionResult AddFile() { var chemin = (string)MySession.GetChemin(); HttpPostedFileBase file = Request.Files[0]; //File will be saved in application root FileSystemItem fileSystemItem = FileSystemItem.GetElement((string)MySession.GetChemin(), MySession.GetUser().Id); // TODO check is session user is null bool result = fileSystemItem.CreateFile(file); return(RedirectToAction("Index", "Home", new { Chemin = chemin })); }