public string CreateDocument(string user, string reason) { var refFileInfo = _env.ContentRootFileProvider.GetFileInfo($"Resources/{ReferenceDocName}.docx"); if (!refFileInfo.Exists) { return(null);//NotFound("reference certificate not available"); } string guid = Guid.NewGuid().ToString(); var newFilePath = _env.ContentRootFileProvider.GetFileInfo($"Resources/{guid}.docx").PhysicalPath; new System.IO.FileInfo(refFileInfo.PhysicalPath).CopyTo(newFilePath); // https://docs.microsoft.com/en-us/office/open-xml/how-to-change-text-in-a-table-in-a-word-processing-document // https://stackoverflow.com/questions/18316873/replace-text-in-word-document-using-open-xml using (WordprocessingDocument doc = WordprocessingDocument.Open(newFilePath, true)) { Dictionary <DocumentFieldsEnum, string> data; switch (user.ToLower()) { case "alexandra ungureanu": data = DocumentData.DataForAlexandraUngureanu(reason); break; case "dan magirescu": data = DocumentData.DataForDanMagirescu(reason); break; default: data = DocumentData.NewData(user, reason); break; } foreach (var pair in data) { ReplaceText(doc, DocumentData.DocumentFields[pair.Key], pair.Value); } } return(guid); }