/// <summary> /// Generate zip file with database backup. /// </summary> /// <param name="connectionString"></param> /// <param name="databaseName"></param> /// <returns>Path to the generated file.</returns> protected static string GenerateZipFile(string connectionString, string databaseName) { FileInfo backupFile = BackupDatabase(connectionString, databaseName); string zipFile = ZipManager.GenerateZipFile(backupFile, databaseName); return(zipFile); }
protected void btnSavePictures_Click(object sender, EventArgs e) { //create zip package and redirect to it string zipShortFilename = string.Format("Charts-{0}-{1}.zip", deStartDate.Date.ToString("dd.MM.yyyy"), deFinishDate.Date.ToString("dd.MM.yyyy")); string zipFilename = Path.Combine(Server.MapPath(Config.UploadDirectory), zipShortFilename); FileInfo[] files = new FileInfo[this.FilesToSave.Count]; for (int i = 0; i < files.Length; i++) { files[i] = new FileInfo(this.FilesToSave[i]); } ZipManager.GenerateZipFile(files, zipFilename); Response.Redirect(string.Format("~/{0}/{1}", Config.UploadDirectory, zipShortFilename)); }
/// <summary> /// Pack log files, older than first day of previous month. /// </summary> protected void PackOldFiles() { // Get log files older than first day of previous month DateTime olderDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(-1).Date; FileInfo[] oldFiles = LoggerUtilities.GetOlderLogFiles(olderDate); if (oldFiles.Length == 0) { return; } // Generate ZIP file from old log files string zipFile = ZipManager.GenerateZipFile(oldFiles, ZipManager.CreateZipFile()); // Create name for ZIP file string logsPath = Path.Combine( HttpContext.Current.Server.MapPath("~/"), ConfigSettings.ApplicationLogFolder); string zipFileName = Path.Combine(logsPath, String.Concat("Logs", olderDate.ToString("yyyyMM"), ".zip")); #region Check if file exists and add appender bool isZipExists = System.IO.File.Exists(zipFileName); int appender = 1; while (isZipExists) { zipFileName = Path.Combine(logsPath, String.Concat("Logs", olderDate.ToString("yyyyMM"), "-", appender, ".zip")); isZipExists = System.IO.File.Exists(zipFileName); appender++; } #endregion // Move ZIP file into the log directory System.IO.File.Move(zipFile, zipFileName); // Delete old log files LoggerUtilities.DeleteLogFiles(oldFiles); }
/// <summary> /// Generate zip file with selected log files. /// </summary> /// <param name="selectedFiles"></param> /// <returns>Path to the generated file.</returns> protected static string GenerateZipFile(FileInfo[] selectedFiles) { string zipFile = ZipManager.GenerateZipFile(selectedFiles, ZipManager.CreateZipFile()); return(zipFile); }