What is the ContentType of Response ?

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

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?
 
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/
===================================
 
Thanks,
I still have a question.
What is the difference if I use
Response.ContentType = "application/xml";
 
ad said:
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.
 

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