public ActionResult GetJson(IEnumerable <int> idList) { var json = service.GetJson(idList); if (!Directory.Exists(Server.MapPath("~/Backups/Brochure"))) { Directory.CreateDirectory(Server.MapPath("~/Backups/Brochure")); } var fileName = $"{DateTime.Now:dd.MM.yyyy hh-m-ss}.json"; var filePath = Server.MapPath("~/Backups/Brochure") + $"\\{fileName}"; System.IO.File.WriteAllText(filePath, json); var plainTextBytes = Encoding.UTF8.GetBytes(filePath); return(new HttpStatusCodeResult(200)); }
public BackupFileViewModel GetJson([FromBody] IEnumerable <int> idList) { var json = service.GetJson(idList); var pathToFolder = MapLocalPath($"\\Backups\\{this.GetType().Name.Replace("Controller", "")}"); if (!Directory.Exists(pathToFolder)) { Directory.CreateDirectory(pathToFolder); } var fileName = $"{DateTime.Now:dd.MM.yyyy hh-m-ss}.json"; var filePath = pathToFolder + $"\\{fileName}"; System.IO.File.WriteAllText(filePath, json); BackupFileViewModel file = new BackupFileViewModel { FileNameBase64 = backupFileService.GetBase64EncodedFileName(fileName, Encoding.UTF8.CodePage), User_Id = User.Identity.GetUserId() }; var fileId = backupFileService.CreateBackupFile(file, pathToFolder); return(backupFileService.GetBackupFileViewModel(fileId)); }