Esempio n. 1
0
 public static void ZipIFormFile(string path, Microsoft.AspNetCore.Http.IFormFile File)
 {
     using (var archive = ZipFile.Open(path + ".zip", ZipArchiveMode.Create))
     {
         archive.CreateEntryFromFile(FilepathUtils.GetPath(File, true), File.FileName);
     }
 }
Esempio n. 2
0
        public static string SaveFile(Microsoft.AspNetCore.Http.IFormFile file)
        {
            Boolean knownExt = FileExtention.GetExtention(file) != null;

            String path = null;

            try
            {
                file.CopyTo(new FileStream(FilepathUtils.GetPath(file, !knownExt), FileMode.Create));

                if (knownExt)
                {
                    path = FilepathUtils.GetPath(file, false).Substring(1);
                }
                else
                {
                    ZipFileUtils.ZipIFormFile(FilepathUtils.GetPath(file, false), file);

                    File.Delete(FilepathUtils.GetPath(file, true));

                    path = (FilepathUtils.GetPath(file, false) + ".zip").Substring(1);
                }
            }
            catch (System.Exception)
            {
                if (knownExt)
                {
                    path = FilepathUtils.GetPath(file, false).Substring(1);
                }
                else
                {
                    path = (FilepathUtils.GetPath(file, false) + ".zip").Substring(1);
                }
            }

            System.Console.WriteLine(path);
            return(path);
        }