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 }));
        }
Exemplo n.º 2
0
        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 }));
        }
Exemplo n.º 3
0
        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 }));
        }
Exemplo n.º 4
0
        public ActionResult DisplayContent(String name)
        {
            var      chemin = (string)MySession.GetChemin();
            FileInfo file   = new FileInfo(Path.Combine(Debug.LocalStorage(), name));

            if (chemin != null)
            {
                file = new FileInfo(Path.Combine(Debug.LocalStorage(), chemin.ToString(), name));
            }

            if (file.Exists)
            {
                if (ViewerModel.ExtensionImage.ToList().Contains(file.Extension.ToLower()))
                {
                    return(RedirectToAction("Index", "DisplayImage", new { Name = name }));
                }

                else if (ViewerModel.ExtensionMovie.ToList().Contains(file.Extension.ToLower()))
                {
                    return(RedirectToAction("Index", "DisplayMovie", new { Name = name }));
                }

                else if (ViewerModel.ExtensionText.ToList().Contains(file.Extension.ToLower()))
                {
                    return(RedirectToAction("Index", "DisplayText", new { Name = name }));
                }
            }
            return(RedirectToAction("Index", "Home", new { Chemin = chemin }));
        }
Exemplo n.º 5
0
        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 }));
        }
Exemplo n.º 6
0
        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 }));
        }
Exemplo n.º 7
0
        // 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"));
        }
Exemplo n.º 8
0
        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"));
        }
Exemplo n.º 9
0
        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 }));
        }
Exemplo n.º 10
0
        // GET: DisplayMovie
        public ActionResult Index(string name)
        {
            var chemin = (string)MySession.GetChemin();

            FileInfo file = new FileInfo(Path.Combine(Debug.LocalStorage(), name));

            if (chemin != null)
            {
                string fileURL = Path.Combine(Debug.LocalStorage(), chemin.ToString(), name);
                file = new FileInfo(fileURL);
            }
            if (file.Exists)
            {
                if (ViewerModel.ExtensionMovie.ToList().Contains(file.Extension.ToLower()))
                {
                    DisplayContent displayContent = new DisplayContent();

                    displayContent.ProcessStart(file.ToString());
                }
            }

            return(RedirectToAction("Index", "Home", new { Chemin = chemin }));
        }
Exemplo n.º 11
0
        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 }));
        }