After publishing to a Windows Server 2016 server using the File Sytem method, the method stops working through Visual Studio 2017.
Button action on the view.
<form asp-action="CreateWordFile" asp-route-id="@Model.Mains.ETP_MainId"> <input type="submit" class="btn btn-info" value="СФОРМИРОВАТЬ WORD - ФАЙЛ"> </form> The method itself:
[HttpPost] public async Task<IActionResult> CreateWordFile(int id, ETP_Main main) { main = await _context.ETP_Mains.SingleOrDefaultAsync(m => m.ETP_MainId == id); var webRoot = _env.WebRootPath; //явно указываю путь к папке wwwwroot var pathEtp = Path.Combine(webRoot, "files", "Etp.docx"); //путь к шаблону var pathDoc = Path.Combine(webRoot, "files", "Doc.docx"); //путь к файлу который буду заполнять using (WordprocessingDocument wEtp = WordprocessingDocument.Open(pathEtp, true)) //открываю файл Etp.doc { string docText = null; using (StreamReader sr = new StreamReader(wEtp.MainDocumentPart.GetStream())) //создаю поток чтения { docText = sr.ReadToEnd(); //читаю файл } using (WordprocessingDocument wDoc = WordprocessingDocument.Open(pathDoc, true)) //открываю файл в который буду вносить изменения { using (StreamWriter sw = new StreamWriter(wDoc.MainDocumentPart.GetStream(FileMode.Create))) //создаю поток записи { sw.Write(docText); //записываю текст в новый файл } } } var pathFile = Path.Combine(webRoot, "files", "Doc.docx"); return PhysicalFile(pathFile, "application/msdoc", "Doc.docx"); } Mistake:
http://192.168.0.158/ETP/CreateWordFile/30 HTTP 404 NOT FOUND The method should not follow the link ... / CreateWordFile / 30. The method should read / write and start downloading the file.
Libraries in nuget:
DocumentFormat.OpenXml jQuery Microsoft.AspNetCore.All Microsoft.AspNetCore.Server.IISIntegration Microsoft.VisualStudio.Web.CodeGeneration.Design
Trace.WriteLine();according to the method and set the record in the file of these messages to determine where the problem is. - Bulson