What is the ContentType of Response ?

Discussion in 'ASP .Net' started by ad, Jul 14, 2006.

  1. ad

    ad Guest

    I create a MemoryStream form a dataset:

    MemoryStream sm= new MemoryStream();
    dsHealth.WriteXml(sm);

    I use
    Response.Write()
    to send this XML MemoryStream as file to client.

    What is the ContentType of Response I must set?
    ad, Jul 14, 2006
    #1
    1. Advertising

  2. If you were sending XML to be inserted into HTML, you'd set the ContentType :

    Response.ContentType = "text/xml";
    Response.ContentEncoding = Encoding.UTF8;

    But, since what you want to do is send a file, not render it, you need to serialize the objects
    to a memory stream and then send the bytes in the memory stream buffer over the TCP connection.

    See this article for sample code :
    http://www.thescripts.com/forum/thread178613.html

    There's more sample code at :
    http://www.developerfusion.co.uk/show/4415/5/




    Juan T. Llibre, asp.net MVP
    aspnetfaq.com : http://www.aspnetfaq.com/
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    ===================================
    "ad" <> wrote in message news:...
    >I create a MemoryStream form a dataset:
    >
    > MemoryStream sm= new MemoryStream();
    > dsHealth.WriteXml(sm);
    >
    > I use
    > Response.Write()
    > to send this XML MemoryStream as file to client.
    >
    > What is the ContentType of Response I must set?
    >
    >
    >
    >
    >
    >
    Juan T. Llibre, Jul 14, 2006
    #2
    1. Advertising

  3. ad

    ad Guest

    Thanks,
    I still have a question.
    What is the difference if I use
    Response.ContentType = "application/xml";




    "Juan T. Llibre" <> ¼¶¼g©ó¶l¥ó·s»D:...
    > If you were sending XML to be inserted into HTML, you'd set the
    > ContentType :
    >
    > Response.ContentType = "text/xml";
    > Response.ContentEncoding = Encoding.UTF8;
    >
    > But, since what you want to do is send a file, not render it, you need to
    > serialize the objects
    > to a memory stream and then send the bytes in the memory stream buffer
    > over the TCP connection.
    >
    > See this article for sample code :
    > http://www.thescripts.com/forum/thread178613.html
    >
    > There's more sample code at :
    > http://www.developerfusion.co.uk/show/4415/5/
    >
    >
    >
    >
    > Juan T. Llibre, asp.net MVP
    > aspnetfaq.com : http://www.aspnetfaq.com/
    > asp.net faq : http://asp.net.do/faq/
    > foros de asp.net, en español : http://asp.net.do/foros/
    > ===================================
    > "ad" <> wrote in message
    > news:...
    >>I create a MemoryStream form a dataset:
    >>
    >> MemoryStream sm= new MemoryStream();
    >> dsHealth.WriteXml(sm);
    >>
    >> I use
    >> Response.Write()
    >> to send this XML MemoryStream as file to client.
    >>
    >> What is the ContentType of Response I must set?
    >>
    >>
    >>
    >>
    >>
    >>

    >
    >
    ad, Jul 14, 2006
    #3
  4. "ad" <> wrote in message
    news:...
    > Thanks,
    > I still have a question.
    > What is the difference if I use
    > Response.ContentType = "application/xml";


    By default, they are the same but in theory, you could (on Windows) bind a
    different clsid to them, so when the content type would be application/xml
    you could open XmlSpy (for instance) and when it is text/xml IE.


    > "Juan T. Llibre" <>
    > ¼¶¼g©ó¶l¥ó·s»D:...
    >> If you were sending XML to be inserted into HTML, you'd set the
    >> ContentType :
    >>
    >> Response.ContentType = "text/xml";
    >> Response.ContentEncoding = Encoding.UTF8;
    >>
    >> But, since what you want to do is send a file, not render it, you need to
    >> serialize the objects
    >> to a memory stream and then send the bytes in the memory stream buffer
    >> over the TCP connection.
    >>
    >> See this article for sample code :
    >> http://www.thescripts.com/forum/thread178613.html
    >>
    >> There's more sample code at :
    >> http://www.developerfusion.co.uk/show/4415/5/
    >>
    >>
    >>
    >>
    >> Juan T. Llibre, asp.net MVP
    >> aspnetfaq.com : http://www.aspnetfaq.com/
    >> asp.net faq : http://asp.net.do/faq/
    >> foros de asp.net, en español : http://asp.net.do/foros/
    >> ===================================
    >> "ad" <> wrote in message
    >> news:...
    >>>I create a MemoryStream form a dataset:
    >>>
    >>> MemoryStream sm= new MemoryStream();
    >>> dsHealth.WriteXml(sm);
    >>>
    >>> I use
    >>> Response.Write()
    >>> to send this XML MemoryStream as file to client.
    >>>
    >>> What is the ContentType of Response I must set?
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>

    >>
    >>

    >
    >
    Egbert Nierop \(MVP for IIS\), Jul 14, 2006
    #4
    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. alien2_51

    Response.ContentType

    alien2_51, Jun 26, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    751
    alien2_51
    Jun 26, 2003
  2. Bart Vanwesemael
    Replies:
    1
    Views:
    523
    William F. Robertson, Jr.
    Jul 28, 2003
  3. TJS
    Replies:
    5
    Views:
    1,052
    Alvin Bruney
    Nov 19, 2003
  4. =?Utf-8?B?RXlhbCBaaW5kZXI=?=

    Response.ContentType and Viewstate problem

    =?Utf-8?B?RXlhbCBaaW5kZXI=?=, Apr 22, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    453
    =?Utf-8?B?RXlhbCBaaW5kZXI=?=
    Apr 22, 2004
  5. Katie
    Replies:
    8
    Views:
    264
    Anthony Jones
    Aug 17, 2006
Loading...

Share This Page