Outputing text file to response stream

  • Thread starter Thread starter Mantorok
  • Start date Start date
M

Mantorok

Hi all

I have the contents of a text file that I would like to output to the
response stream, however IE thinks it is XML and comes up with and error,
here is the code:

Response.ContentType = "test/plain";
Response.OutputStream.Write(buffer, 0, buffer.Length);

Response.End();


Any ideas?
Thanks
KEv
 
Quick guess - shouldn't this read

Response.ContentType = "text/plain";

and not

Response.ContentType = "test/plain";

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 
See my 2nd message.

Kev

John Timney (ASP.NET MVP) said:
Quick guess - shouldn't this read

Response.ContentType = "text/plain";

and not

Response.ContentType = "test/plain";

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 
try adding a filename header

Response.ContentType = "text/plain";
Response.OutputStream.Write(buffer, 0, buffer.Length);
Response.AddHeader "Content-Disposition", "inline;filename=temp.txt"

or change your content type to text/html

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 
Excellent, I added the filename header and that worked. What is the
filename actually used for?

Thanks
Kev
 
Most browsers have no understanding of what text/plain actually is - so it
interprets the stream as something else. The filename simply tells it that
its a .txt file extension and the system should treat it accordingly.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 
Thanks for your help John.

Kev

John Timney (ASP.NET MVP) said:
Most browsers have no understanding of what text/plain actually is - so it
interprets the stream as something else. The filename simply tells it
that its a .txt file extension and the system should treat it accordingly.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 

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