1

I Have created a method to download file from server. It 's seem that I can save the file to client, but the saved file is always an empty file( file size = 0KB ).

Did I miss something in my code?

My Front-end code:

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
      Html.RenderAction("DownloadDocument", "Document", new { documentNode = Umbraco.TypedContent(CurrentPage.Id) });
}

And bellow is my DownloadDocument method in Document controller:

                var fileName = "myFile.docx"
                var filePath = @"D:\myFile.docx"
                Response.ContentType = "application/octet-stream";
                Response.AppendHeader("Content-Disposition", $"attachment; filename={fileName}");
                Response.TransmitFile(Server.MapPath(filePath));
                Response.Flush();
                Response.End();

P/S: If I include File Length in the header, it throw a Failed - Network error from my client browser:

Response.AddHeader("Content-Length", new System.IO.FileInfo(fileName).Length.ToString());

Any help is appreciate! Thanks!

mm8
  • 150,971
  • 10
  • 50
  • 74
Nhan Phan
  • 1,252
  • 1
  • 13
  • 29

0 Answers0