HTTPResponse capture or redirect stream

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

I have developed an ASP.NET web page with a VB.net for the code behind.
I would like to redirect the output of the web page so I can send it as
an Email. Or Redirect the HTTPResponse stream on the server to a
file. Any ideas would be appreciated.

Thank you
Paul
 
Hi Paul

The following will e.g. write a word file to the browser. In addition
it prompts for a 'Save As...' dialog, even if the browser is normally
set to open this kind of file.

HTH

Martin

'Set Headers
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/x-msdownload"
Response.AppendHeader("Content-Disposition",
"attachment;filename=Test.doc")
'Create Stream
Dim FileStream As System.IO.FileStream = New
System.IO.FileStream("C:\Inetpub\wwwroot\WebApplication3\pro­gclient\1\assets\files\documents\key\2212005210406_1_1.doc",

System.IO.FileMode.Open)
Dim FileSize As Long = FileStream.Length
Dim bBuffer(FileSize) As Byte
FileStream.Read(bBuffer, 0, Convert.ToInt32(FileSize))
FileStream.Close()
'Output To Client
Response.BinaryWrite(bBuffer)
Response.End()
 
Hi Paul

The following will e.g. write a word file to the browser. In addition
it prompts for a 'Save As...' dialog, even if the browser is normally
set to open this kind of file.

HTH

Martin

'Set Headers
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/x-msdownload"
Response.AppendHeader("Content-Disposition",
"attachment;filename=Test.doc")
'Create Stream
Dim FileStream As System.IO.FileStream = New
System.IO.FileStream("C:\Inetpub\wwwroot\WebApplication3\pro­gclient\1\assets\files\documents\key\2212005210406_1_1.doc",

System.IO.FileMode.Open)
Dim FileSize As Long = FileStream.Length
Dim bBuffer(FileSize) As Byte
FileStream.Read(bBuffer, 0, Convert.ToInt32(FileSize))
FileStream.Close()
'Output To Client
Response.BinaryWrite(bBuffer)
Response.End()
 
I was not clear. I do not need to display a document. I need to capture
the HTTP response to a file or redirect (not response.redirect) it to
multiple email address. All this must occure on the server.

Paul
 
Hello Paul,

If you want to save the output to a file, look at the Filter property of
the HttpResponse object.

If you want to email the output, look at RenderControl method of the Page
class.

string output = "";
using (StringWriter sw = new StringWriter())
using (HtmlTextWriter writer = new Html32TextWriter(sw))
{
myPageInstace.RenderControl(writer);
output = sw.GetStringBuilder().ToString();
}

// at this point, output has the html of the rendered page
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top