I want to download a file with an unknown format in my MVC controller.
Here is my code
public static void DownloadAttachment(string Name,string physicalPath ) {
if (System.IO.File.Exists(physicalPath))
{
System.IO.FileInfo file = new System.IO.FileInfo(physicalPath);
byte[] fileB = File.ReadAllBytes(physicalPath);
HttpContext context = HttpContext.Current;
context.Response.ClearHeaders();
context.Response.Clear();
context.Response.AddHeader("content-disposition", "attachment; filename="+Name+";");
context.Response.ContentType = "application/force-download";
context.Response.BinaryWrite(fileB.ToArray());
context.Response.Flush();
context.Response.End();
}
}
But it is not working but doesn't give any error.
How do I solve this problem?