Directing a file to the output response...

Discussion in 'ASP .Net' started by Stu, Sep 28, 2005.

  1. Stu

    Stu Guest

    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
     
    Stu, Sep 28, 2005
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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. Justin Gengo, Sep 28, 2005
    #2
    1. Advertising

  3. Stu

    Karl Seguin Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
    >
     
    Karl Seguin, Sep 28, 2005
    #3
  4. Stu

    Stu Guest

    Many thanks - and so simple as well :)




    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    wrote in message news:%23$...
    > 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" <> wrote in message
    > news:...
    >> 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
    >>
    >>
    >>

    >
    >
     
    Stu, Sep 29, 2005
    #4
  5. Stu

    ai4u Guest

    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
    -----------------------------------------------------------------------
    Posted via http://www.codecomments.co
    -----------------------------------------------------------------------
     
    ai4u, Apr 27, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve C. Orr [MVP, MCSD]
    Replies:
    0
    Views:
    443
    Steve C. Orr [MVP, MCSD]
    Jun 3, 2004
  2. =?Utf-8?B?Q2hyaXNB?=

    directing page output to a New window from server-side?

    =?Utf-8?B?Q2hyaXNB?=, Dec 9, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    347
    =?Utf-8?B?Q2hyaXNB?=
    Dec 9, 2006
  3. Tim Slattery
    Replies:
    0
    Views:
    353
    Tim Slattery
    Oct 16, 2007
  4. Murugesh

    directing output of system()

    Murugesh, Mar 23, 2005, in forum: Perl Misc
    Replies:
    9
    Views:
    130
    J├╝rgen Exner
    Mar 24, 2005
  5. Rajpreet
    Replies:
    1
    Views:
    454
    Rajpreet
    Jan 18, 2008
Loading...

Share This Page