Hi,

So in my .net core MVC web app, I am currently generating a .docx file using OpenXML SDK. Productivity Tool.

Currently, when the user fills in the form on my View and hits Submit, the OpenXML code is triggered and the word doc is generated, and emailed to a user. What I now need is the file to be also available to download for that user.

Here is my code so far (in my HttpPost method):

string fileName = referralFormsLocation + constructedFilename+".docx";
//Generate Word Document referral form - uses Open XML SDK GeneratedClassOpenXML.CreatePackage(fileName, LoggedInUser, emailaddressToSendForm.EmailAddress);

//downloadable file for user
ExportFile(fileName);

Within CreatePackage, the word doc is generated and emailed to the user. fileName contains a path to the generated document.

[HttpGet]
public IActionResult ExportFile(string filePath)
{
return File(System.IO.File.ReadAllBytes(filePath),
contentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
fileDownloadName: "MySheet.docx");

}

Currently, when my code hits the ExportFile method, nothing happens, the user is not prompted for a download.

What am I doing wrong? Thanks
no comments yet
Be the first to share what you think!

source