title: How to show download dialog before file is ready to download?
body: <p>I'm getting a file from a database in byte [] format and want user to see download dialog before Linq will take it from the database. It's in C# and ASP.NET.</p>
  
  <p>Now, it's like this:</p>
  
  <ol>
  <li>User choose a file, click on it.</li>
  <li>In code I get id of file clicked and using Linq I'm downloading.</li>
  <li>Then I send the file by Response.OutputStream.Write(content, 0,
  content.Length);</li>
  <li>Before a file is downloaded from the database user won't see any
  download dialog.</li>
  </ol>
  
  <p><strong>What can I do if I want users to see the download dialog before file is downloaded?</strong></p>
  
  <p>Code:<br>
  Getting file by id:</p>
  
  <pre><code>public static byte[] getFile(Guid id)
  {
      var linqFile =  from file in MyDB.Files
                      where file.IdPliku.Equals(id)
                      select new
                      {
                          Content = file.Content
                      };
  
       return linqFile.ToList().FirstOrDefault().Content.ToArray();
  }
  </code></pre>
  
  <p>Saving file:</p>
  
  <pre><code>public void SaveFile(Guid fileID, string filename, string mimeTypes)
  {
      try
      {
          byte[] content = FileService.getFile(fileID);
          Response.ClearContent();
          Response.ClearHeaders();
          Response.ContentType = mimeTypes;
          Response.AppendHeader("Accept-Ranges", "bytes");
          Response.AppendHeader("Content-Range", string.Format("0-{0}/{1}", content.Length, content.Length));
          Response.AppendHeader("Content-Length", content.Length.ToString());
          Response.AppendHeader("Content-Encoding", "utf-8");
          Response.AppendHeader("Content-Type", Response.ContentType);
          Response.AppendHeader("Content-Disposition", "attachment; filename= " + HttpUtility.UrlEncode(filename));
          Response.OutputStream.Write(content, 0, content.Length);
          //Response.BinaryWrite(content);
          Response.Flush();
      }
      finally
      {
          Response.Close();
      }
  }
  </code></pre>
  
  <p>You are my hope.</p>