private void BindData() { StringBuilder allCheckboxesToSelect = new StringBuilder(); BackupItems backupItems = AutoUpdateManager.GetFilesInBackup(this.Target); BackupCreationDate = Format.DateTime(AutoUpdateManager.GetBackupInfo(this.Target).CreationTime); List <Data.RestorableFile> restorableFiles = new List <ACSSAuth.Management.Content.AutoUpdate.Data.RestorableFile>(); foreach (UpdateItem packageFile in backupItems.PackageFiles) { string includedImage; string protectedImage; if (packageFile.IsIncluded == false) { includedImage = Page.ResolveUrl("~/Images/dg_excluded.png"); } else { includedImage = Page.ResolveUrl("~/Images/dg_included.png"); } if (packageFile.IsProtected == true) { protectedImage = Page.ResolveUrl("~/Images/dg_protected.png"); } else { protectedImage = Page.ResolveUrl("~/Images/dg_unprotected.png"); } restorableFiles.Add(new ACSSAuth.Management.Content.AutoUpdate.Data.RestorableFile() { Container = packageFile.PackageName, DateCreated = Format.DateTime(packageFile.FileInfo.CreationTime), LastModified = Format.DateTime(packageFile.FileInfo.LastWriteTime), Name = packageFile.Name, Type = "Packages", IncludedImage = includedImage, ProtectedImage = protectedImage, RelativeDirectory = packageFile.RelativeDirectory //.Substring(packageFile.PackageName.Length).TrimStart(new char [] {'\\'}) }); } gvBackupFiles.DataSource = restorableFiles; gvBackupFiles.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { string backupName = Request.Params["backup"]; string itemType = Request.Params["type"]; string container = Request.Params["container"]; string relativeDirectory = Request.Params["rel"]; string filename = Request.Params["file"]; string rootDirectory = String.Empty; string filepath = AutoUpdateManager.GetFilePath(itemType, container, relativeDirectory, filename); UpdateItem itemToDownload = null; if (String.IsNullOrEmpty(backupName) == false) // Download the file from a backup. { if (AutoUpdateManager.IsFilenameOrDirectorySafe(backupName) == false) { throw new Exception("backup name is invalid."); } BackupItems backupItems = AutoUpdateManager.GetFilesInBackup(backupName); if (itemType == "Packages") { itemToDownload = backupItems.PackageFiles.FirstOrDefault(p => p.Name == filename && p.PackageName == container && p.RelativeDirectory == relativeDirectory); } else { throw new Exception("Unsupported itemType: " + itemType); } } else // Download the file from a package. { if (itemType == "Packages") { List <UpdateItem> itemsInPackage = AutoUpdateManager.GetFilesInUpdatePackage(container); itemToDownload = itemsInPackage.FirstOrDefault(p => p.Name == filename && p.PackageName == container && p.RelativeDirectory == relativeDirectory); } else { throw new Exception("Unsupported itemType: " + itemType); } } if (itemToDownload == null) { Response.StatusCode = 404; Response.End(); } string mimeType = Utility.GetMimeType(Path.GetExtension(itemToDownload.Name)); byte[] outputBytes = File.ReadAllBytes(itemToDownload.FileInfo.FullName); Response.ContentType = mimeType; Response.AddHeader("Content-Disposition", "attachment; filename=" + itemToDownload.Name); Response.AddHeader("ContentLength", outputBytes.Length.ToString()); Response.BinaryWrite(outputBytes); }