Question: Rather than displaying a PNG in the browser window, I'd like the action result to trigger the file download dialogue box (you know the open, save as, etc). I can get this to work with the code below using an unknown content type, but the user then has to type in .png at the end of the file name. How can I accomplish this behavior without forcing the user to type in the file extension?

```
    public ActionResult DownloadAdTemplate(string pathCode)
    {
        var imgPath = Server.MapPath(service.GetTemplatePath(pathCode));
        return base.File(imgPath, "application/unknown");
    }

```

### Solution....

```
    public ActionResult DownloadAdTemplate(string pathCode)
    {
        var imgPath = Server.MapPath(service.GetTemplatePath(pathCode));
        Response.AddHeader("Content-Disposition", "attachment;filename=DealerAdTemplate.png");
        Response.WriteFile(imgPath);
        Response.End();
        return null;
    }

```

Answer: 
You need to set the following headers on the response:

* `Content-Disposition: attachment; filename="myfile.png"`
* `Content-Type: application/force-download`
The correct way to download file in your case is to use `FileResult` class.

```
 public FileResult DownloadFile(string id)
{
try
{
    byte[] imageBytes =  ANY IMAGE SOURCE (PNG)
    MemoryStream ms = new MemoryStream(imageBytes);
    var image = System.Drawing.Image.FromStream(ms);
    image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
    var fileName = string.Format("{0}.png", "ANY GENERIC FILE NAME");
    return File(ms.ToArray(), "image/png", fileName);
}
catch (Exception)
{
}
return null;
}

```