public ContentResult Generate([System.Web.Http.FromBody] string nameTemplate, string json) { FillDocxController fillDocx = new FillDocxController(); InfoVuln.GetInstance().ProcessDocx(nameTemplate, json); var timeStamp = InfoVuln.GetInstance().TimeStamp; if (fillDocx.IsExistFile(timeStamp + ".Report.docx").IsSuccessStatusCode) { return(base.Content($"<a href='/api/filldocx/download?filename={timeStamp}.Report.docx'>{timeStamp}.Report.docx</a>", "text/html")); } //$"/api/filldocx/download?filename={helper.TimeStamp}.Report.docx"; else { return(base.Content("Not Found File")); } //string fullName = Server.MapPath("~/Render/" + helper.TimeStamp + ".Report.docx"); //byte[] fileBytes = GetFile(fullName); //return File( // fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, Server.MapPath("~/Render/" + helper.TimeStamp + ".Report.docx")); //if (fillDocx.IsExistFile(helper.TimeStamp + ".Report.docx").StatusCode == System.Net.HttpStatusCode.OK) // return fillDocx.Download(helper.TimeStamp + ".Report.docx"); //else return new HttpResponseMessage(System.Net.HttpStatusCode.NotFound); }
public ActionResult UploadFile(HttpPostedFileBase files) { string ext = Path.GetExtension(files.FileName); if (ext == ".json") { FileUpload model = new FileUpload(); List <FileUpload> list = new List <FileUpload>(); DataTable dtFiles = GetFileDetails(); foreach (DataRow dr in dtFiles.Rows) { list.Add(new FileUpload { FileId = @dr["Id"].ToString(), FileName = @dr["FILENAME"].ToString(), FileUrl = @dr["FILEURL"].ToString(), JsonName = @dr["JSONNAME"].ToString(), JsonUrl = @dr["JSONURL"].ToString() }); } model.FileList = list; if (files != null) { //var Extension = Path.GetExtension(files.FileName); var timeStamp = InfoVuln.GetInstance().TimeStamp; if (!Directory.Exists(Server.MapPath($"~/UploadedFiles/{timeStamp}"))) { Directory.CreateDirectory(Server.MapPath($"~/UploadedFiles/{timeStamp}")); } string path = Path.Combine(Server.MapPath($"~/UploadedFiles/{timeStamp}"), files.FileName); model.FileUrl = Url.Content(Path.Combine($"~/UploadedFiles/{timeStamp}/", files.FileName)); model.FileName = files.FileName; if (SaveFile(model)) { files.SaveAs(path); TempData["AlertMessage"] = "Uploaded Successfully !!"; return(RedirectToAction("Index", "Template")); } else { ModelState.AddModelError("", "Error In Add File. Please Try Again !!!"); } } else { ModelState.AddModelError("", "Please Choose Correct File Type !!"); return(View(model)); } } return(RedirectToAction("Index", "Template")); }
public HttpResponseMessage Generate([FromBody] string nameTemplate, string json) { try { InfoVuln.GetInstance().ProcessDocx(nameTemplate, json); return(IsExistFile($"{InfoVuln.GetInstance().TimeStamp}.Report.docx")); } catch (Exception) { //Console.WriteLine(ex.Message); return(new HttpResponseMessage() { StatusCode = HttpStatusCode.NotFound }); } }