Directing a file to the output response...

S

Stu

Hi,

I need to push a .eml file (MS email pickup format) to the browser when the
user clicks on a button. The file is outside of the web space so I used this
method (which worked with word docs). This nearly works....but the email
file has the web page contents tagged on the end of it. It looks like the
Response.Clear() is not working.

'load file in to byte array
Dim s As New FileStream("c:\Test.eml", FileMode.Open)
Dim bytes() As Byte
ReDim bytes(s.Length)
s.Read(bytes, 0, s.Length)

'output file to the browser
Response.Clear()
Response.ContentType = "application/octet-stream; name=Test.eml"
Response.AddHeader("content-transfer-encoding", "binary")
Response.AddHeader("content-disposition", "attachment;filename=Test.eml")
Response.ContentEncoding = System.Text.Encoding.GetEncoding(1251)
Response.BinaryWrite(bytes)
s.Close()
s = Nothing

Anyone got any ideas?

Stu
 
S

S. Justin Gengo

Stu,

I don't know if this will work or not, but I was just taking a look at some
code I wrote to output a datagrid as an excel spreadsheet and I'm using
Response.Charset = "" before the output.

Try it out, maybe that's what's left over?

I've got my fingers crossed.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
K

Karl Seguin

You need to call Response.End() to stop the rest of the request from
happening.

Karl
 
A

ai4u

I tried this. I created a webform1.aspx and added the iframe and calle
the webform2.aspx in that iframe.
webform2.aspx had the below code:
Try
Dim s As New FileStream("d:\Test\Re_ Test message.eml"
FileMode.Open)
Dim bytes() As Byte
ReDim bytes(s.Length)
s.Read(bytes, 0, s.Length)

'output file to the browser
Response.Clear()
Response.Charset = ""
Response.ContentType = "application/octet-stream; name=Re
Test message.eml"
Response.AddHeader("content-transfer-encoding", "binary")
Response.AddHeader("content-disposition"
"attachment;filename=Re_ Test message.eml")
Response.ContentEncoding
System.Text.Encoding.GetEncoding(1251)
Response.BinaryWrite(bytes)
s.Close()
s = Nothing
Response.End()
Catch ex As Exception
Response.Write(ex.Message)
End Try

But it is still opeing the .eml/.msg file in a different window and no
within the iframe . This is not required.
Any suggestions.

I have to open the .msg / .eml files in the browser just as .doc file
are opened in the native applications within the browser.
Please inform how this can be done.

Alternatively using asp.net 1.1 and vb.net/c# can I open the .msg/.em
files in native application within any placeholder / literal

or any client side scripting

All ideas are welcome.

Thanks in advance


Atu


-
ai4
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top