I have two different web pages that both create text files that are returned to the user via Response.WriteFile.
On the first page, in a button's click event, I have the following:
SendFileResponse(Response, sFileName, "Data_" & sNow & ".csv")
In the other page, I instantiate a class and then, within a try - catch block, call a class method that makes the following calle:
SendFileResponse(HttpContext.Current.Response, sServerFilename, "Extract_" & DateTime.Now.ToString("yyyyMMdd_HHmmss") & ".csv")
Both pages inherit from a base page which traps and logs any errors.
The code for SendFileResponse is as follows:
Public Sub SendFileResponse( _
ByRef oResponse As HttpResponse, _
ByVal sServerFileName As String, _
ByVal sUserFileName As String)
Dim fiDownload As FileInfo = New FileInfo(sServerFileName)
oResponse.ClearHeaders() ' Required to clear caching headers
oResponse.AddHeader("Content-Disposition", "attachment; filename=" & sUserFileName)
oResponse.ContentType = "application/octet-stream"
The first page works fine without throwing any errors. The second page often throws the following exception: System.Threading.ThreadAbo
n: Thread was being aborted.
Can someone explain why one page throws the error and the other doesn't?
Thanks in advance.