You're reading the file line by line, so the line returned will never contain \r
, \n
or \r\n
- as those are line separators.
The simplest approach is just to load the whole lot into memory, remove all the line breaks, then write it out:
string text = File.ReadAllText(sourceFileName);
text = text.Replace("\r", "").Replace("\n", "");
File.WriteAllText(sourceFileName, text);
Of course if you only want to remove carriage returns, just remove the .Replace("\n", "")
in the above code.
EDIT: Now that we can see your file, there is no XML version 10, which suggests that the document is corrupt before you even get it. You should stop at this point and work backwards towards the source until you can get a valid XML file. There's no point in continuing with what you've currently got.