title: HTML is appended with exported .csv document
body: <p>I am generating a string with comma separated variables and trying to export that. The problem is that the whole .html page is getting appended alongwith the exported .csv file.</p>
  
  <p>I have two instances of code, one in local server and other in testing server. I am using the same database in both, the codebase is same in both still, there is an issue while exporting the .csv file.</p>
  
  <p>Following is the code I am using for exporting...</p>
  
  <pre><code>//name - Name of File to save
  //text - Comma separated string
  private void ExportToCSV(string fileName, string text)
      {
          Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".csv");
          if (text != null &amp;&amp; text.Length &gt; 0)
          {
              Response.AddHeader("Content-Length", text.Length.ToString());               
              Response.Output.Write(text);
          }
      }
  </code></pre>
  
  <p>I have tried using <code>Response.Write(text)</code>, but still having the same issue.</p>
  
  <p>This is the output I am getting when I get the exported .csv file...</p>
  
  <pre><code>SEARCH DATE,USER TYPE,CITY
  20-08-2015,TM,Chicago
  20-08-2015,TM,New York
  20-08-2015,TM,London
  20-08-2015,TM,London
  20-08-2015,TM,London
  20-08-2015,TM,Cape Town
  20-08-2015,TM,Mumbai
  20-08-2015,TM,Ottawa
  20-08-2015,TM,Mumbai
  20-08-2015,TM,Istanbul
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;&lt;title&gt;
      Search Report
  &lt;/title&gt;
      &lt;script src="Jquery/jquery-1.9.1.js" type="text/javascript"&gt;&lt;/script&gt;
  
      &lt;script src="Jquery/jquery-ui-1.9.2.custom/js/jquery-ui-1.9.2.custom.js"
          type="text/javascript"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
          var t = false;
          window.alert = function(message) {
              $(document.createElement('div'))
          .attr({ title: 'Alert', 'class': 'alert' })
          .html(message)
          .dialog({
              buttons: { OK: function() { $(this).dialog('close'); } },
              close: function() { $(this).remove(); },
              draggable: true,
              modal: true,
              resizable: false,
              width: 'auto'
          });
          };
  
          $(function() {
  
              var useragent = navigator.userAgent;
              var bName = (useragent.indexOf('Opera') &gt; -1) ? 'Opera' : navigator.appName;
              var pos = useragent.indexOf('MSIE');
              var bVer = "";
              if (pos &gt; -1) {
                  $('li').has('ul').mouseover(function() {
                      $(this).children('ul').show();
                  }).mouseout(function() {
                      $(this).children('ul').hide();
                  })
              }
  
  
          });
  
      &lt;/script&gt;
  
      .
      .
      .
      .
      .
      .
  
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I am unable to figure out the root cause of this issue due to which this is happening. If someone can explain the reason along with the solution, it would be of immense help. Thanks.</p>