Saturday, 14 September 2013

ASP.NET Export - Response not ending?

ASP.NET Export - Response not ending?

I'm trying to export some text to a text file, and that part works fine.
The trouble is that the text files get a bunch of HTML/.NET output at the
bottom of them... In other words, it's like the response isn't ending and
the page is trying to write the rest of the page. Here's the code:
Private Sub WriteData(ByRef Context As System.Web.HttpContext,
Data As List(of String), fileName as String)
With Context.Response
.Clear()
.ClearHeaders()
.ClearContent()
.AddHeader("content-disposition", String.Format("attachment;
filename={0}", fileName))
.ContentType = contentType
End With
For Each curValue in Data
Context.Response.Write(curValue)
Context.Response.Write(Environment.NewLine)
Next
Context.ApplicationInstance.CompleteRequest()
Context.Response.End()
End Sub
To call this, I just pass the HttpContext.Current and a list of data.
Does anybody know why this might happen? I'm not sure how to interpret it,
and I've looked all over without much luck. My assumption was that the
response wasn't actually ending with "Response.End()"...
Thanks,
Mike

No comments:

Post a Comment