Beispiel #1
0
        public IActionResult DownloadFile(VizhenerViewModel model)
        {
            try
            {
                MemoryStream           mem          = new MemoryStream();
                WordprocessingDocument wordDocument = WordprocessingDocument.Create(mem, WordprocessingDocumentType.Document, true);

                MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();

                mainPart.Document = new Document();
                Body      body = mainPart.Document.AppendChild(new Body());
                Paragraph para = body.AppendChild(new Paragraph());
                Run       run  = para.AppendChild(new Run());
                run.AppendChild(new Text(model.Result));
                mainPart.Document.Save();
                wordDocument.Close();
                mem.Position = 0;

                return(File(mem, "application/docx", "result.docx"));
            }
            catch (Exception)
            {
                model.Error = "Ошибка при создании файла";
                return(View("Index", model));
            }
        }
Beispiel #2
0
 public IActionResult Update(VizhenerViewModel model, IFormFile file)
 {
     if (file == null)
     {
         if (model == null || string.IsNullOrEmpty(model.Message))
         {
             return(RedirectToAction("Index"));
         }
     }
     else
     {
         if (file.Length > 0)
         {
             try
             {
                 model.Message = GetMessageFromFile(file);
             }
             catch (NotSupportedException)
             {
                 model.Error = "Ошибка! Файл имеет расширение отличное от .docx!";
             }
             catch (Exception)
             {
                 model.Error = "Возникла ошибка при чтении файла!";
             }
         }
         else
         {
             model.Error = "Ошибка! Файл пустой!";
         }
     }
     return(View("Index", model));
 }