title: How to download an image with the button click in C#?
body: <p>Is there a way to download an image that was uploaded by the user? I have the following: First, the user click an image from a mosaic to view it in detail; then the image is generated in a asp:image tag, at that step they are supposed to download it with a button click. The problem I have is that the image is generated in a asp:image tag and is not the actual image itself with a name. The code I have to download only gets the image stored in a folder. Below is the code:</p>
  
  <pre><code>protected void btnDownload_Click(object sender, EventArgs e)
  {
      string path = @"C:\inetpub\wwwroot\PSCSearchEngine\MemberPages\Images\live.jpg";        
      System.IO.FileInfo file = new System.IO.FileInfo(path);
      if (file.Exists)
      {
          Response.Clear();
          Response.ContentType = MimeType(Path.GetExtension(path));
          Response.AddHeader("Content-Disposition", 
              string.Format("attachment; filename = {0}",
              System.IO.Path.GetFileName(path)));
          Response.AddHeader("Content-Length", file.Length.ToString("F0"));
          Response.TransmitFile(path);
          Response.End();
      }
      else
      {
          Response.Write("This file does not exist.");
      } 
  }
  </code></pre>
  
  <p>Below is the code that previews the image:</p>
  
  <pre><code>@"~/MemberPages/UpdatePhoto.aspx?SiteKey=" + foo.Site_ID 
      + "&amp;TimeStamp=" + foo.timestamp[n1 - 1];
  </code></pre>