Outputing text file to response stream

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
 
J

John Timney \(ASP.NET MVP\)

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
 
M

Mantorok

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
 
J

John Timney \(ASP.NET MVP\)

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
 
M

Mantorok

Excellent, I added the filename header and that worked. What is the
filename actually used for?

Thanks
Kev
 
J

John Timney \(ASP.NET MVP\)

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
 
M

Mantorok

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

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top