public FilePathResult Download(int id) { var conventionManager = new DataAccess.ConventionManager(); var convention = conventionManager.GetConventionDetail(id); var fileAttachments = conventionManager.GetAttachmentListOfConvention(id).Select(model => model.FileResource).ToList(); var outputDirectory = new DirectoryInfo(string.Format("{0}ExportFiles\\{1}\\{2}", Server.MapPath(@"\"), convention.Name, DateTime.Now.ToString("ddMMyyyyhhmmss"))); var outputDirectoryPathString = System.IO.Path.Combine(outputDirectory.ToString(), ""); var isExists = System.IO.Directory.Exists(outputDirectoryPathString); if (isExists) System.IO.Directory.Delete(outputDirectoryPathString, true); System.IO.Directory.CreateDirectory(outputDirectoryPathString); foreach (var fileAttachment in fileAttachments) { var sourceFilePath = Server.MapPath(fileAttachment.path); var destFilePath = System.IO.Path.Combine(outputDirectoryPathString, fileAttachment.name); if (!System.IO.Directory.Exists(destFilePath)) { System.IO.File.Copy(sourceFilePath, destFilePath, true); } } var zipOutputDirectory = new DirectoryInfo(string.Format("{0}ExportFiles\\{1}", Server.MapPath(@"\"), convention.Name)); var zipOutputDirectoryPathString = System.IO.Path.Combine(zipOutputDirectory.ToString(), (DateTime.Now.ToString("ddMMyyyyhhmmss") + ".zip")); ZipFile.CreateFromDirectory(outputDirectoryPathString, zipOutputDirectoryPathString); return File(zipOutputDirectoryPathString, "application/zip", DateTime.Now.ToString("ddMMyyyyhhmmss") + ".zip"); }
public PartialViewResult UploadAttachment(int id) { var conventionManager = new DataAccess.ConventionManager(); var conventionDetail = conventionManager.GetConventionDetail(id); var conventionAttachments = conventionManager.GetAttachmentListOfConvention(id); ViewData["Attachments"] = conventionAttachments; return PartialView(conventionDetail); }