title: wait till code executes before running redirect
body: <p>I have a page redirect that runs after a string is written to an MSword doc using WebClient and StringBuilder.</p>
  
  <pre><code>        HttpContext.Current.Response.Write(strHTMLContent);
          this.Page.Response.Redirect("http://www.google.com");
          HttpContext.Current.Response.End();
  </code></pre>
  
  <p>However the string never gets written (or it doesn't get the chance to) since the redirect happens instantly.</p>
  
  <p>How can i make my redirect run only until the string Write has occurred?</p>
  
  <p>Thanks guys</p>
  
  <p>This is the code used to generate the MSWord:</p>
  
  <pre><code>        HttpContext.Current.Response.Charset = "";
          HttpContext.Current.Response.ContentType = "application/msword";
          string strFileName = "GenerateDocument" + ".doc";
          HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + strFileName);
          StringBuilder strHTMLContent = new StringBuilder();
  </code></pre>