Triggering a download on Publish
z
Is there a way to trigger a file download in the back office when using Save and Publish? I am using ContentService_Published, to generate an Excel file when using Save and Publish, this part works fine. I'd also like to a file donwload to trigger once the file is saved. I am trying to do something like this:
Copy code
csharp
private void ContentService_Published(Umbraco.Core.Services.IContentService sender, Umbraco.Core.Events.ContentPublishedEventArgs e)
{
  // do stuff to get my content and save the excel file
  if (downloadOnPublish)
  {
      HttpContext.Current.Response.Clear();
      HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
      HttpContext.Current.Response.AddHeader("Content-Disposition", $"attachment; filename=myExcelFile.xlsx");     
      byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
      HttpContext.Current.Response.BinaryWrite(fileBytes);      
      HttpContext.Current.Response.End();
  }
}