4

I'm generating a CSV-file on the fly in ASP .Net C#, and writing it directly to the response.

    private void ExportToResponse(string textCsv, string fileName)
    {
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.ContentType = "text/csv";
        HttpContext.Current.Response.ContentEncoding = Encoding.Unicode;
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName + ".csv");
        HttpContext.Current.Response.Write(textCsv);
        HttpContext.Current.Response.End();
    }

And in most cases this works well, but in some cases I get an error ("this website can not be displayed in Internet Explorer"). I suspect that the reason is that this file is getting to large for the response. In that case, how to I extend the limit of the response length?

I was hoping I could do this in the web.config-file, similar to how you set the mexRequestLength-property to the httpRuntime-element (http://msdn.microsoft.com/en-us/library/e1f13641.aspx).

Thanks!

linnkb
  • 515
  • 3
  • 9
  • 24
  • are you hosting your site in IIS, if yes which version? – Imran Rizvi Mar 20 '12 at 11:46
  • It better to send it in parts and not all in ones. Also disable the buffer, and use a handler to send it, not from inside the page because the session will lock the other users and you going to have timeouts. – Aristos Mar 20 '12 at 12:05
  • 1
    I have a rule of thumb for stuff like this, if you have to ask what the limit of something is, you're probably doing it wrong. ;) Good luck none the less – Alexandre Mar 20 '12 at 12:36

0 Answers0