title: Dynamically setting hyperlink's NavigateUrl to a file path does not work
body: <p>I am attempting to set a HyperLink control's <code>NavigateUrl</code> path to a file, so that the user can click on the link and download the file.  In my C# and ASPX code, the URL appears properly set, but clicking on the link causes nothing to happen; right-clicking on the link and attempting to save the link attempts to save <code>download.htm</code>.</p>
  
  <p>Behind the scenes, I'm creating the file in the temp directory and moving it to an available location for download.  This part works; I'm including it for reference.</p>
  
  <pre><code>    private string MoveFile(string file_name, string file_path)
      {
          string tempdir = HttpContext.Current.Server.MapPath( ConfigurationManager.AppSettings["docs_folder"] );
          string new_file_name = Path.Combine( tempdir, Path.GetFileName( file_name ) );
          try
          {
              if (File.Exists( new_file_name ))
              {
                  File.Delete( new_file_name );
              }
              File.Move( file_name, new_file_name );
          }
          catch (Exception e)
          {
              string message = e.Message;
          }
          return new_file_name;
      }
  </code></pre>
  
  <p>And here's how I'm presently setting the URL:</p>
  
  <pre><code>        string download_file = downloader.DownloadFiles(); //Ultimately returns the path from the MoveFile method
          hl_download.NavigateUrl = "file:///" + HttpUtility.UrlPathEncode( download_file ).Replace("\\","//");
          hl_download.Visible = true;
  </code></pre>
  
  <p>My output looks like:
  <code>file:///C://users//codes%20with%20hammer//documents//visual%20studio%202012//Projects//Download%20File//Download%20File//Archive_to_download.zip</code></p>
  
  <p>When I drop this URL directly into the browser, the file properly downloads.  So why doesn't it work on the hyperlink?</p>
  
  <p>I also tried setting the property on a static hyperlink.  Same result.  For comparison:
  <code>&lt;asp:HyperLink ID="HyperLink1" runat="server" Visible="True" NavigateUrl="file:///C:/users/codes%20with%20hammer/documents/visual%20studio%202012/Projects/Download%20File//Download%20File//Archive_to_download.zip"&gt;click me&lt;/asp:HyperLink&gt;</code></p>
  
  <p><em>Revised</em></p>
  
  <p>My ASHX page has the following code in <code>ProcessRequest</code>:</p>
  
  <pre><code>        context.Response.Clear();
          context.Response.ContentType = "application/octet-stream";
          context.Response.AddHeader( "Content-Disposition", "attachment; filename=" + Path.GetFileName(  download_file ));
          context.Response.WriteFile( context.Server.MapPath( download_file ) );
          context.Response.End();
  </code></pre>
  
  <p>Perhaps I should move this into my code-behind file?</p>