Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult GetDocFile(int LetterId, string FileName, string LetterField, string Content)
- {
- Content = Content.Replace(""", "");
- MemoryStream stream = new MemoryStream();
- OperationDetails op = new OperationDetails();
- if (!Directory.Exists(Server.MapPath("~/Uploads/LetterTemplate")))
- {
- Directory.CreateDirectory(Server.MapPath("~/Uploads/LetterTemplate"));
- }
- string filename = Server.MapPath("~/Uploads/LetterTemplate/" + FileName + ".docx");
- CommonHelper.CommonHelper.DeleteSingleFile(filename);
- string html = Content;
- try
- {
- using (WordprocessingDocument package = WordprocessingDocument.Create(stream, WordprocessingDocumentType.Document))
- {
- MainDocumentPart mainPart = package.MainDocumentPart;
- if (mainPart == null)
- {
- mainPart = package.AddMainDocumentPart();
- new Document(new Body()).Save(mainPart);
- }
- HtmlConverter converter = new HtmlConverter(mainPart);
- converter.ParseHtml(html);
- var body = package.MainDocumentPart.Document.Body;
- mainPart.Document.Save();
- }
- System.IO.File.WriteAllBytes(filename, stream.ToArray());
- op = objReportingDB.UpdateLetterTemplate(LetterId, FileName, LetterField, LetterId == 0 ? 1 : 2, Content);
- if (op.Success)
- {
- op.Message = "Letter template saved successfully";
- }
- else
- {
- op.Message = "Error while saving letter template! ";
- }
- }
- catch (Exception ex)
- {
- op.Success = false;
- op.Message = "Error while saving letter template! ";
- }
- return Json(op, JsonRequestBehavior.AllowGet);
- }
Add Comment
Please, Sign In to add comment