public ActionResult GenerateData(XmlLogIndexViewModel model) { try { //string folderPath = @"D:\Temp\EMS\zipFolder\"; string folderPath = ConfigurationManager.AppSettings["XmlLogPath"]; string zipName = "XmlLogZip" + "_" + DateTime.Now.ToString("ddMMyyyyHHmmss") + "_" + CurrentUser.USER_ID + ".zip"; var input = new BackupXmlLogInput(); input.FolderPath = folderPath; input.FileZipName = folderPath + zipName; input.FileName = model.FileName; input.Month = model.Month; _nLogBll.BackupXmlLog(input); return(Json(new { success = true, zipName }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { string message = ex.Message; return(Json(new { success = false, message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult BackupXml(XmlLogIndexViewModel model) { //var input = new NlogGetByParamInput() //{ // FileName = model.FileName, // Month = model.Month //}; //_nLogBll.DeleteDataByParam(input); //AddMessageInfo("Success backup data", Enums.MessageInfoType.Success); //return RedirectToAction("Index"); try { //string folderPath = @"D:\Temp\EMS\zipFolder\"; string folderPath = ConfigurationManager.AppSettings["XmlLogPath"]; string zipName = "XmlLogZip" + "_" + DateTime.Now.ToString("ddMMyyyyHHmmss") + "_" + CurrentUser.USER_ID + ".zip"; var input = new BackupXmlLogInput(); input.FolderPath = folderPath; input.FileZipName = folderPath + zipName; input.FileName = model.FileName; input.Month = model.Month; _nLogBll.BackupXmlLog(input); // Read bytes from disk //byte[] fileBytes = System.IO.File.ReadAllBytes(Server.MapPath("~/Directories/hello/sample.zip")); byte[] fileBytes = System.IO.File.ReadAllBytes(folderPath + zipName); // Return bytes as stream for download return(File(fileBytes, "application/zip", zipName)); } catch (Exception ex) { AddMessageInfo(ex.Message, Enums.MessageInfoType.Error); return(RedirectToAction("Index")); } }
public void BackupXmlLog(BackupXmlLogInput input) { var inputParam = new NlogGetByParamInput(); inputParam.FileName = input.FileName; inputParam.Month = input.Month; var listData = GetNlogByParam(inputParam); var listFile = listData.DistinctBy(c => c.FileName).Select(x => x.FileName).ToList(); //check file foreach (var file in listFile) { if (!System.IO.File.Exists(input.FolderPath + file)) { throw new BLLException(ExceptionCodes.BLLExceptions.LogXmlNotFound); } } foreach (var nlogDto in listData) { //get data var data = _repository.GetByID(nlogDto.Nlog_Id); if (data != null) { _repository.Delete(data); } } //ZipHelper.CreateZip(); //backup to zip file ZipHelper.CreateZip(listFile, input.FolderPath, input.FileZipName); _uow.SaveChanges(); }