private FileResult createBackupFromModel(ExportModel exportModel) { string HomeDirectory = ((BaseCatalogDir)System.Web.Configuration.WebConfigurationManager.GetSection("katalogBazowyDanych")).BaseDir; Backup backup = new Backup(HomeDirectory); string fileName = prepareAttachmentName(exportModel); return File(backup.ZipFilesInRange(exportModel), "application/force-download", fileName); }
public Stream ZipFilesInRange(ExportModel movie) { Stream zipStream = new MemoryStream(); using (ZipFile zip = new ZipFile()) { List<DirectoryElementList> directoryList = GetDirectoryElementList(movie.FromDate, movie.ToDate); foreach (DirectoryElementList element in directoryList) { zip.AddDirectory(element.Directory, element.DirectoryInArchive); } zip.Save(zipStream); zipStream.Position = 0; } return zipStream; }
private static string prepareAttachmentName(ExportModel exportModel) { return exportModel.FromDate.ToString("yyyy-MM-dd") + "_" + exportModel.ToDate.ToString("yyyy-MM-dd") + ".zip"; }
public FileResult CreateLastDays(int days) { ExportModel exportModel = new ExportModel(); exportModel.FromDate = exportModel.ToDate.AddDays(-1d*days); return createBackupFromModel(exportModel); }
public FileResult Create(ExportModel exportModel) { return createBackupFromModel(exportModel); }