0

Have tried both "\r\n" and environment.newline in VS2003 to get newline. We are writing text in stringbuilder using "\r\n" or environment.newline and saving it in IO file. NewLine break is not working in the file when it is opened in IE11 whereas it works if it is opened in notepad. This also works if it is opened in older version of IE8.

The part of the code is:

 StringBuilder cdataDescription = new StringBuilder();

 cdataDescription.Append("* This is an install activity which passed through SYR.").Append(newline);
                cdataDescription.Append("\r\n");
                //For CSI
                cdataDescription.Append(" Please dispatch to the IBG  * ");
                cdataDescription.Append("\r\n");
                cdataDescription.AppendLine();
                cdataDescription.Append("test");
                cdataDescription.Append("\r\n");
                cdataDescription.Append("General Information");
                cdataDescription.Append("\r\n");
                cdataDescription.Append("---------------------------------------");
                cdataDescription.Append("\r\n");

string result = string.empty;
result = cdataDescription.ToString();

return result;
Subramanyam M
  • 335
  • 2
  • 6
  • 18
  • 3
    So are you opening a plain-text file in the browser, or is it HTML? There's not enough context here... – Jon Skeet Sep 23 '15 at 11:55
  • 1
    use
    for new line if saving it to .html file
    – shreesha Sep 23 '15 at 11:59
  • Why not just use `AppendLine` instead of `Append`? Expecting Notepad and any version of IE to display a file the same way is not reasonable. One is for editing text files the other is meant for viewing html files. – juharr Sep 23 '15 at 12:06
  • Tried using AppenLine and this is also not working. This is an .xml file opened in browser. – Upasana Singh Sep 24 '15 at 10:31
  • @UpasanaSingh If this is XML then what do you care about how it is rendered? Strictly speaking, xml is data and has nothing to do with presentation. – Igor Sep 25 '15 at 17:02
  • The browser ignores all newline characters (and contiguous spaces are reduced to a single space). If you want line breaks in the browser you need to use a `
    ` tag.
    – Craig W. Sep 25 '15 at 17:03

1 Answers1

-2

Ideally a new line char is "\n" as far as writing a text file is conserned. You might need to check the charset that your using to write to the file. Windows notepad supports only ASCII you might what to open your file in Norepad++ as it supports different character sets.

Also be aware of UNIX and Windows style.

  • @UpasanaSingh, check out this link [Similar Question](http://stackoverflow.com/questions/2986297/line-break-in-xml). I think link here is a similar question. For your problem you need to use
    .
    – Suman Mummaneni Sep 30 '15 at 15:06