Call Back to Previous Header

criticalzell

New member
Joined
May 17, 2006
Messages
2
Programming Experience
1-3
spacer.gif
I have a method that triggers the download diolog box. My problem is when the dialog box is triggered, the page does not reflect the codes that I wrote. For example in this code, I call the method dowloadFile, after the Download dialog box is triggered, nothing happens to the page. It is supposed to display the summary message. I think it has something to do with with the httpheaders. Can anyone help how to return to the previous header.

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
 
Back
Top