J
Jerry Camel
The following code throws a "Thread was being aborted" exception at the Response.End line. Even if I catch the exception, the code that follows is never executed. (Because the thread was being aborted...?) What does this mean? Why is it happening? How do I fix it? I've tried everything I can think of. I've wrapped all the code in try blocks, but the thread exception is the only one being thrown. Please help... Thanks.
Jerry
sCommand = "SELECT * FROM FD_Files " & _
"WHERE (HashName = '" & e.CommandArgument() & "')"
Dim daFiles As New SqlDataAdapter(sCommand, sqlCnxn)
Dim dsFiles As New DataSet()
daFiles.Fill(dsFiles, "FD_Files")
Dim dr As DataRow = dsFiles.Tables("FD_Files").Rows(0)
Dim fStream As FileStream
Dim bytesToGo As Long
Dim bytesRead As Long
Dim byteBuffer(2048) As Byte
fStream = New FileStream("C:\DepotRoot\" & e.CommandArgument(), FileMode.Open, _
FileAccess.Read, FileShare.Read)
bytesToGo = fStream.Length
Response.BufferOutput = False
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/octet-stream"
Response.AppendHeader("Content-Disposition", "attachment; filename=""" & dr("FileName") & """")
Response.AppendHeader("Content-Length", fStream.Length)
Response.Flush()
While (bytesToGo > 0)
If (Response.IsClientConnected) Then
bytesRead = fStream.Read(byteBuffer, 0, 2048)
Response.OutputStream.Write(byteBuffer, 0, bytesRead)
Response.Flush()
bytesToGo -= bytesRead
Else
bytesToGo = -1
End If
End While
fStream.Close()
Response.End()
Jerry
sCommand = "SELECT * FROM FD_Files " & _
"WHERE (HashName = '" & e.CommandArgument() & "')"
Dim daFiles As New SqlDataAdapter(sCommand, sqlCnxn)
Dim dsFiles As New DataSet()
daFiles.Fill(dsFiles, "FD_Files")
Dim dr As DataRow = dsFiles.Tables("FD_Files").Rows(0)
Dim fStream As FileStream
Dim bytesToGo As Long
Dim bytesRead As Long
Dim byteBuffer(2048) As Byte
fStream = New FileStream("C:\DepotRoot\" & e.CommandArgument(), FileMode.Open, _
FileAccess.Read, FileShare.Read)
bytesToGo = fStream.Length
Response.BufferOutput = False
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/octet-stream"
Response.AppendHeader("Content-Disposition", "attachment; filename=""" & dr("FileName") & """")
Response.AppendHeader("Content-Length", fStream.Length)
Response.Flush()
While (bytesToGo > 0)
If (Response.IsClientConnected) Then
bytesRead = fStream.Read(byteBuffer, 0, 2048)
Response.OutputStream.Write(byteBuffer, 0, bytesRead)
Response.Flush()
bytesToGo -= bytesRead
Else
bytesToGo = -1
End If
End While
fStream.Close()
Response.End()