0

I have a problem when trying to download a file from server to client. On click the save file prompt is shown like its supposed to be, but it doesnt point to the file I want to download, but rather to my aspx page? In other words, it doesnt download the file i wish to download, but it downloads the page upon which the download link is located. Really weird... It seems almost as if the file i specify for download is being completely ignored/has no effect...

if (File.Exists(Server.MapPath(driversLocation + name + ".zip")))
{
    FileInfo fileInfo = new FileInfo(Server.MapPath(driversLocation) + name + ".zip");

    Response.Clear();
    Response.AddHeader("Content-Disposition", "inline;attachment; filename=" + name + ".zip");
    Response.AddHeader("Content-Length", fileInfo.Length.ToString());
    Response.ContentType = "application/download";
    Response.Flush();
    Response.TransmitFile(Server.MapPath(driversLocation) + name + ".zip");
    Response.End();
 }

Any help would be appreciated!

Cyclonecode
  • 29,115
  • 11
  • 72
  • 93
Alen
  • 145
  • 1
  • 1
  • 10

1 Answers1

0

The problem was the "inline". There are some other things to tweak to make the code easier to read:

Related post: Content-Disposition:What are the differences between "inline" and "attachment"?

FileInfo fileInfo = new FileInfo(Server.MapPath(driversLocation + name + ".zip"));

if (fileInfo.Exists)
{
     Response.Clear();
     Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
     Response.AddHeader("Content-Length", fileInfo.Length.ToString());
     Response.ContentType = "application/x-zip-compressed";
     Response.TransmitFile(fileInfo.FullName);
     Response.End();
}
Community
  • 1
  • 1
MikeSmithDev
  • 15,731
  • 4
  • 58
  • 89