Re: format of txt file lost

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Using &nbsp to replace the spaces is indeed the correct way to go. In
order to do it on the server side, you can call the HtmlEncode method on the
HttpServerUtility instance exposed by the page you are on (through the
Server property). This will take a string and return an HTML-encoded
string, or you can write it to a TextWriter if you want.

It should be noted that this isn't a "problem" with the browser, but
rather, the way HTML is supposed to behave, this is ^expected^ behavior.

On the browser side, you are most likely going to want to use a
fixed-width font for the presentation of this data, as spaces in
non-fixed-width fonts usually tend to be small, and you won't have that much
space between them.

Either that, or as Michael says, use tables to perform the layout (which
would require more parsing on your end).


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

<mpetrotta@xxxxxxxxx> wrote in message
news:1190651776.457141.313800@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Sep 24, 9:18 am, "doomsday...@xxxxxxxxx" <doomsday...@xxxxxxxxx>
wrote:
I have a txt file that I am reading and displaying on a page. The text
in the txt is...
------------------------------------------------------------------------------------------
Discontinued P/N Replacement P/N
71-TNPW0603100KBEBD 71-TNPW0603100KBETY
71-TNPW0603100RBEBD 71-TNPW0603100RBETY
71-TNPW0603105KBEBD 71-TNPW0603105KBETY
------------------------------------------------------------------------------------------

When I use this method to display the text on a page...
------------------------------------------------------------------------------------------
StreamReader fsText = fi.OpenText();

StringBuilder sb = new StringBuilder();

while (!fsText.EndOfStream)
{
sb.Append(fsText.ReadLine() + "<br />");
}
------------------------------------------------------------------------------------------

The text comes out like this...
------------------------------------------------------------------------------------------
Discontinued P/N Replacement P/N
71-TNPW0603100KBEBD 71-TNPW0603100KBETY
71-TNPW0603100RBEBD 71-TNPW0603100RBETY
71-TNPW0603105KBEBD 71-TNPW0603105KBETY
------------------------------------------------------------------------------------------

Is there any way to get the text to display exactly like it is in the
txt file?
Thanks

It looks like you're creating an HTML file. If you open the HTML file
in a text editor, you'll see that the spaces are there as expected.
The culprit here is your browser, collapsing multiple spaces to a
single space. See http://www.sightspecific.com/~mosh/WWW_FAQ/nbsp.html
for more information.

What can you do? You can substitute, as the page above discusses, a
&nbsp for a space. Or you can substitute it only when you see
multiple spaces in sequence. Or you can convert the formatted table
to a proper HTML table, if possible.

This is an HTML issue, not a C# one, so you may get more help in an
HTML newsgroup.

Michael



.



Relevant Pages

  • Re: Total drop down boxes
    ... The first method consists in manually writing the content in the file, either in the HTML file directly or using some automated method on a server. ... The second one consists in writing the mass HTML in a javascript variable, then document.writing the content of this variable on the document. ...
    (comp.lang.javascript)
  • Re: Post to another page (MasterPage, In JavaScript)
    ... It doesn't have to, as html does. ... I'm pretty sure that a content area doesn't have to be inside a server form... ... As a workaround I inserted an iframe, which is a simple .html file, ... into the contentarea, then pasted the PayPal code into the .html file, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: HTML document in Word ignores changes
    ... should just edit the HTML file in Notepad. ... > desginated directory on the server. ... > I create the document in Word and then save it as a html document. ...
    (microsoft.public.word.vba.general)
  • Re: How can I "include" an HTML file from another server?
    ... HTML file from another server and puts it in. ... [Your user agent does not support frames or is currently ...
    (comp.infosystems.www.authoring.html)
  • Re: How to do a post back when user press enter.
    ... It is hosted on a web server, ... the client browser, which is designed to read and interpret HTML. ... UI, via the event handler. ...
    (microsoft.public.dotnet.framework.aspnet)