tags:

views:

234

answers:

3

I'm using Response.WriteFile("mymenu.aspx") to write a plain text file out to an area in a MasterPage. Unfortunately it's also printing out an unknown character represented by the square character. The contents of the menu file are as followings:

<ul>
  <li><a href="Accounts">Accounts</a></li>
</ul>

The square character is what is causing my menu to display incorrectly, pushing it down about 20 pixels. I tested putting just the HTML in the master page instead of including the file and it works fine which mean it must be down to the Response.WriteFile function. I don't suppose anyone else has encountered this problem?

EDIT: I tried the following as well, just to really make sure I wasn't doing anything stupid and that the file didn't contain anything dodgy.

<%
   Dim tw As New System.IO.StreamReader(Server.MapPath("menu.aspx"))
   For Each s As String In tw.ReadToEnd
      Response.Write(s)
   Next
%>

It worked. But that still doesn't explain Response.WriteFile behaviour.

A: 

This sounds like a character encoding issue. Is this file in the same encoding as the page your using it from?

Edit

Open the file up in a hex editor make sure there are no weird characters in there.

JoshBerke
I've tried Response.ContentType = "plain/text" without any luck.
Kezzer
Ohh I saw your comment to Hector...
JoshBerke
Aye, seems more like a problem to do with Response.WriteFile as opposed to the actual file itself. I tried it with a plain text file too and still had the exact same problem. I can re-create it and have the same problem.
Kezzer
Hmm weird you use Fiddler to watch the html over the wire?
JoshBerke
Check my edit. Strange behaviour.
Kezzer
A: 

Have a look at your text file in an editor that will show all characters including carriage returns, line feeds etc. (Notepad++ is my choice). File may have an unusual eof marker or other encoding issue from the software that created the file.

HectorMac
That was the first thing I checked, and I deal with incorrect character sets all the time. Definitely not a problem here.
Kezzer
A: 

I tested your code and it rendered correctly for me.

I have seen ASP.NET alter incoming XML strings in WebMethods before. Save the text to a file on disk before you Response.Write it to compare. Check your CSS for your LI style.

rick schott