This is code used in my filemanager for downloading. It's modified from DNN core filedownload, which was modified from the DNN 2.x version of my filemanager before the re-write. I know I tried several other methods for sending the file to the client, and this so far seems to work best.
Dim objResponse As HttpResponse = HttpContext.Current.Response
objResponse.ClearContent()
objResponse.ClearHeaders()
objResponse.AppendHeader("content-disposition", "attachment; filename=""" + finfo.Name + """")
objResponse.AppendHeader("Content-Length", finfo.Length.ToString())
objResponse.ContentType = strGetContentType(finfo.Extension)
Dim fileStream As Stream = Nothing
fileStream = New FileStream(finfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
Dim objStream As IO.Stream = fileStream
Try
WriteStream(objResponse, objStream)
Catch ex As Exception
objResponse.Write("Error : " & ex.Message)
Finally
If IsNothing(objStream) = False Then
' Close the file.
objStream.Close()
End If
End Try
objResponse.Flush()
objResponse.End()