criticalzell
New member
- Joined
- May 17, 2006
- Messages
- 2
- Programming Experience
- 1-3

If brError.HasError Then
'file error occured, alert user
Dim _download As New HRS.Utility.DownloadFile(fupFileToUpload.FileName)
_download.DownloadFile(brError.Text.ToString.Substring(10))
SetPanels()
lblError.Text = brError.Summary
End If
Public Sub DownloadFile(ByVal fileContent As String)
Dim _fileContent As System.IO.Stream = New System.IO.MemoryStream(System.Text.ASCIIEncoding.Default.GetBytes(fileContent))
'send stream to user
Dim buffer(1048576) As Byte
Dim readCount As Integer = 10000
Dim maxBytes As Integer = 10000
Dim _length As Integer
Dim dataToRead As Long = _fileContent.Length
System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream"
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename = " & FileName)
While dataToRead > 0
If System.Web.HttpContext.Current.Response.IsClientConnected Then
If readCount < dataToRead Then
_length = _fileContent.Read(buffer, 0, readCount)
Else
_length = _fileContent.Read(buffer, 0, dataToRead)
End If
System.Web.HttpContext.Current.Response.OutputStream.Write(buffer, 0, _length)
System.Web.HttpContext.Current.Response.Flush()
ReDim buffer(1048576) ' Clear the buffer
dataToRead = dataToRead - _length
Else
dataToRead = -1
End If
End While
System.Web.HttpContext.Current.Response.Close()
End Sub