473,394 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

What ContentType for text?

Hi;

I am writing the output of a page directly using IHttpHandler,
IRequireSessionState and if it is a text file I set
HttpContext.Response.ContentType = "text/plain". But when it displays I get
an error telling me it's not a legal xml file.

Any ideas?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Jul 20 '06 #1
5 8572
Hello Dave,

As for the httphandler issue, I remember that you've ever posted a similiar
issue about rendering out some certain content in httphandler and encounter
error. Is this similar to that one? Yes, the txt file's mime type is
"text/plain".

I'm not sure about your detailed code logic, here is a simple test
httphandler which flush out some txt content:

===================
public void ProcessRequest(HttpContext context)
{
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.ClearContent();

context.Response.Write("Hello World.");

context.Response.End();
}
==================

BTW, are you using the generic handler ( the ashx ) in VS 2005? If so, this
could be causing some problem since the generic handler may add some
additional content info internally that cause any non-xml/xhtml content
display error at client browser. You can test through a typical custom
httphandler (register in the web.config <httpHandlerssection) to see
whether it works.

If you meet any further problem, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial

response from the community or a Microsoft Support Engineer within 1
business day is

acceptable. Please note that each follow up response may take approximately
2 business days

as the support professional working with you may need further investigation
to reach the

most efficient resolution. The offering is not appropriate for situations
that require

urgent, real-time or phone-based interactions or complex project analysis
and dump analysis

issues. Issues of this nature are best handled working with a dedicated
Microsoft Support

Engineer by contacting Microsoft Customer Support Services (CSS) at

http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 21 '06 #2
Hi;

Still doesn't work. Here is what I am getting:

The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then
click the Refresh button, or try again later.
--------------------------------------------------------------------------------

Invalid at the top level of the document. Error processing resource
'http://localhost:2634/portal/report-create.aspx?wr_id=...

XYZ Consulting Corporation Invoice Invoice
^

Here is my code:
public class ReportCreate : IHttpHandler, IRequiresSessionState
{
....
public void ProcessRequest(HttpContext context)
{
....
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.ClearContent();

string str = GetContentType(format);
context.Response.ContentType = str; // "text/plain"
context.Response.BinaryWrite(((MemoryStream)report .GetReport()).GetBuffer());

context.Response.End();
}

Here is my web.config:
<httpHandlers>
<add verb="*" path="report-create.aspx" type="ReportCreate"/>
<add verb="*" path="report-view.aspx" type="ReportView"/>
<add verb="*" path="template-file.aspx" type="TemplateFile"/>
</httpHandlers>

Any ideas?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm


"Steven Cheng[MSFT]" wrote:
Hello Dave,

As for the httphandler issue, I remember that you've ever posted a similiar
issue about rendering out some certain content in httphandler and encounter
error. Is this similar to that one? Yes, the txt file's mime type is
"text/plain".

I'm not sure about your detailed code logic, here is a simple test
httphandler which flush out some txt content:

===================
public void ProcessRequest(HttpContext context)
{
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.ClearContent();

context.Response.Write("Hello World.");

context.Response.End();
}
==================

BTW, are you using the generic handler ( the ashx ) in VS 2005? If so, this
could be causing some problem since the generic handler may add some
additional content info internally that cause any non-xml/xhtml content
display error at client browser. You can test through a typical custom
httphandler (register in the web.config <httpHandlerssection) to see
whether it works.

If you meet any further problem, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial

response from the community or a Microsoft Support Engineer within 1
business day is

acceptable. Please note that each follow up response may take approximately
2 business days

as the support professional working with you may need further investigation
to reach the

most efficient resolution. The offering is not appropriate for situations
that require

urgent, real-time or phone-based interactions or complex project analysis
and dump analysis

issues. Issues of this nature are best handled working with a dedicated
Microsoft Support

Engineer by contacting Microsoft Customer Support Services (CSS) at

http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 24 '06 #3
Thanks for your response,

This seems abit strange. I found that you still use the aspx extension for
your custom httphandler, have you tried using a different extension such
as *.txtfile to see whether it works. Also, if convenient, you provide a
simplified repro project so that I can test on my local side.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 24 '06 #4
Use a .txt extension. Some browser, IE in particular, will ignore the
"text/plain" ContentType header, as older web pages sometimes used this
header for HTML pages.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

What You Seek Is What You Get.
"David Thielen" <th*****@nospam.nospamwrote in message
news:D8**********************************@microsof t.com...
Hi;

Still doesn't work. Here is what I am getting:

The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then
click the Refresh button, or try again later.
--------------------------------------------------------------------------------

Invalid at the top level of the document. Error processing resource
'http://localhost:2634/portal/report-create.aspx?wr_id=...

XYZ Consulting Corporation Invoice Invoice
^

Here is my code:
public class ReportCreate : IHttpHandler, IRequiresSessionState
{
...
public void ProcessRequest(HttpContext context)
{
...
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.ClearContent();

string str = GetContentType(format);
context.Response.ContentType = str; // "text/plain"
context.Response.BinaryWrite(((MemoryStream)report .GetReport()).GetBuffer());

context.Response.End();
}

Here is my web.config:
<httpHandlers>
<add verb="*" path="report-create.aspx" type="ReportCreate"/>
<add verb="*" path="report-view.aspx" type="ReportView"/>
<add verb="*" path="template-file.aspx" type="TemplateFile"/>
</httpHandlers>

Any ideas?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm


"Steven Cheng[MSFT]" wrote:
>Hello Dave,

As for the httphandler issue, I remember that you've ever posted a
similiar
issue about rendering out some certain content in httphandler and
encounter
error. Is this similar to that one? Yes, the txt file's mime type is
"text/plain".

I'm not sure about your detailed code logic, here is a simple test
httphandler which flush out some txt content:

===================
public void ProcessRequest(HttpContext context)
{
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.ClearContent();

context.Response.Write("Hello World.");

context.Response.End();
}
==================

BTW, are you using the generic handler ( the ashx ) in VS 2005? If so,
this
could be causing some problem since the generic handler may add some
additional content info internally that cause any non-xml/xhtml content
display error at client browser. You can test through a typical custom
httphandler (register in the web.config <httpHandlerssection) to see
whether it works.

If you meet any further problem, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

================================================= =

Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial

response from the community or a Microsoft Support Engineer within 1
business day is

acceptable. Please note that each follow up response may take
approximately
2 business days

as the support professional working with you may need further
investigation
to reach the

most efficient resolution. The offering is not appropriate for situations
that require

urgent, real-time or phone-based interactions or complex project analysis
and dump analysis

issues. Issues of this nature are best handled working with a dedicated
Microsoft Support

Engineer by contacting Microsoft Customer Support Services (CSS) at

http://msdn.microsoft.com/subscripti...t/default.aspx.

================================================= =

This posting is provided "AS IS" with no warranties, and confers no
rights.


Jul 24 '06 #5
that was it - thanks

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm


"Kevin Spencer" wrote:
Use a .txt extension. Some browser, IE in particular, will ignore the
"text/plain" ContentType header, as older web pages sometimes used this
header for HTML pages.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

What You Seek Is What You Get.
"David Thielen" <th*****@nospam.nospamwrote in message
news:D8**********************************@microsof t.com...
Hi;

Still doesn't work. Here is what I am getting:

The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then
click the Refresh button, or try again later.
--------------------------------------------------------------------------------

Invalid at the top level of the document. Error processing resource
'http://localhost:2634/portal/report-create.aspx?wr_id=...

XYZ Consulting Corporation Invoice Invoice
^

Here is my code:
public class ReportCreate : IHttpHandler, IRequiresSessionState
{
...
public void ProcessRequest(HttpContext context)
{
...
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.ClearContent();

string str = GetContentType(format);
context.Response.ContentType = str; // "text/plain"
context.Response.BinaryWrite(((MemoryStream)report .GetReport()).GetBuffer());

context.Response.End();
}

Here is my web.config:
<httpHandlers>
<add verb="*" path="report-create.aspx" type="ReportCreate"/>
<add verb="*" path="report-view.aspx" type="ReportView"/>
<add verb="*" path="template-file.aspx" type="TemplateFile"/>
</httpHandlers>

Any ideas?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm


"Steven Cheng[MSFT]" wrote:
Hello Dave,

As for the httphandler issue, I remember that you've ever posted a
similiar
issue about rendering out some certain content in httphandler and
encounter
error. Is this similar to that one? Yes, the txt file's mime type is
"text/plain".

I'm not sure about your detailed code logic, here is a simple test
httphandler which flush out some txt content:

===================
public void ProcessRequest(HttpContext context)
{
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.ClearContent();

context.Response.Write("Hello World.");

context.Response.End();
}
==================

BTW, are you using the generic handler ( the ashx ) in VS 2005? If so,
this
could be causing some problem since the generic handler may add some
additional content info internally that cause any non-xml/xhtml content
display error at client browser. You can test through a typical custom
httphandler (register in the web.config <httpHandlerssection) to see
whether it works.

If you meet any further problem, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial

response from the community or a Microsoft Support Engineer within 1
business day is

acceptable. Please note that each follow up response may take
approximately
2 business days

as the support professional working with you may need further
investigation
to reach the

most efficient resolution. The offering is not appropriate for situations
that require

urgent, real-time or phone-based interactions or complex project analysis
and dump analysis

issues. Issues of this nature are best handled working with a dedicated
Microsoft Support

Engineer by contacting Microsoft Customer Support Services (CSS) at

http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.



Aug 16 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kamyk | last post by:
Hello all! I have the following problem. I have both text content and image content of the web page created in ASP language. How to do combine these two different types on the page. When I use...
3
by: Webgour | last post by:
How do you reproduce this vbscript in C# <% Response.ContentType = "text/plain" response.write "This is text type" %>
3
by: MJ | last post by:
I'm trying to stream the contenttype of "application/x-java-jnlp-file" via asp.net/c#, but the client only sees it as a plain text file. Example: Response.Clear(); Response.ClearHeader();...
8
by: Bryan Glennon | last post by:
I have an aspx page. If I set the Response.ContentType = "application/voicexml+xml" then when I load browse to the page it downloads the file and opens .Net Studio to allow me to edit it. It...
8
by: DanB | last post by:
This is probably soooo simple but I can't seem to get it. I have a text file that I want users to download via a web page. I want the file to be saved to a default folder (or one that they...
7
by: darrel | last post by:
I'm creating a file upload tool, and want to allow only DOC, XLS, PDF, RTF or TXT files. I am using this to check: if (contentType = "application/msword") _ or (contentType = "application/rtf")...
3
by: ad | last post by:
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...
3
by: letuce dance | last post by:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender,...
9
by: CindyH | last post by:
Hi Trying to get this code to work for http xml post. I need the post to be xml (doc.outerxml) sent in single key name as stream. The following is the post code and code for receiving the request....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.