I have to export very large files as an “excel export”. Since .NET can’t export excel files, I went with simple html tables.
It works fine, but it’s slow.
Is it possible to context.response.write each line as they’re being created instead of building some super huge string and trying to export the whole thing once it’s done?
I could care less what function is used to do this, but I hope you know what I mean. I don’t want to build a string into memory and then try to send it all at once. I’d rather export as I build the table.
Is this possible?
Thanks in advance!
Yes, using context.Response.Write on each line is just fine. If the reason for not wanting to build a large string is server memory use, then you’ll need to turn off response buffering like so:
Otherwise, .NET will just buffer your writes in memory until the end, anyway.
If the reason is execution time, then you may be experiencing performance hits from multiple string concatenations. In that case, you could use the StringBuilder class to construct the table instead.
For example…
More info on response buffering:
http://msdn.microsoft.com/en-us/library/system.web.httpresponse.bufferoutput.aspx
More info on the StringBuilder class:
http://msdn.microsoft.com/en-us/library/system.text.stringbuilder(v=vs.110).aspx