-1

I have 1 excel template in my local system named as "CLIA#OfLabTemplate.xls"

while downloading this template from UI in .net, the template name is getting changed to "CLIA_OfLabTemplate.xls".

What should I do so that the file name will not change ?

    var filepath = Server.MapPath("~/App_Data/CLIA#OfLabTemplate.xls");

Response.ClearContent();

Response.AddHeader("Content-Disposition", "attachment; filename=" + myfile.Name);
                Response.AddHeader("Content-Length", myfile.Length.ToString(CultureInfo.InvariantCulture));
                Response.ContentType = "xls";

                Response.TransmitFile(myfile.FullName);
                Response.End();

1 Answers1

0

A minor comment to start with: it is not a template(.xlt), but a sheet (.xls).

The ContentType should be application/vnd.ms-excel as in this post: https://stackoverflow.com/a/4212908/200824

Or check the next comment of that post to use System.Web.MimeMapping.GetMimeMapping(yourFileName) (.net 4.5) https://stackoverflow.com/a/44677607/200824

Bob Lokerse
  • 476
  • 6
  • 19