469,283 Members | 2,349 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,283 developers. It's quick & easy.

Directing a file to the output response...

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

Nov 19 '05 #1
4 2882
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
"Stu" <s.****@cergis.com> wrote in message
news:uV**************@TK2MSFTNGP09.phx.gbl...
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

Nov 19 '05 #2
You need to call Response.End() to stop the rest of the request from
happening.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Stu" <s.****@cergis.com> wrote in message
news:uV**************@TK2MSFTNGP09.phx.gbl...
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

Nov 19 '05 #3
Stu
Many thanks - and so simple as well :-)


"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%2***************@tk2msftngp13.phx.gbl...
You need to call Response.End() to stop the rest of the request from
happening.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Stu" <s.****@cergis.com> wrote in message
news:uV**************@TK2MSFTNGP09.phx.gbl...
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


Nov 19 '05 #4

I tried this. I created a webform1.aspx and added the iframe and called
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 not
within the iframe . This is not required.
Any suggestions.

I have to open the .msg / .eml files in the browser just as .doc files
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/.eml
files in native application within any placeholder / literal

or any client side scripting

All ideas are welcome.

Thanks in advance
Atul

--
ai4u
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Apr 27 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Peteroid | last post: by
4 posts views Thread by Brian Quigley | last post: by
7 posts views Thread by =?Utf-8?B?TWlrZQ==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.